[CS0120] Making an instance of a class is not an option here
i have a list List<string> pkey in public class login I can modify and read it fine in the login class but anywhere else I can't read it/modifiy how it would I go about doing it? something like Im using websocket-sharp
public class VerifyAccount : WebSocketBehavior
{
protected override void OnMessage(MessageEventArgs e)
{
if (login.pkeys.Contains(e.Data)){
Send("Valid Key!");
}else
{
Send("InvalidKey");
}
}
}
this gives me CS0120, the solutions that people have been saying online is to make an instance of Login in this situation but that would not work for my use case, how would I go about reading it?
Posted Aug 12, 2022, 6:21 PM UTC
You need to have an instance of the class in order to access the instance properties of the Login class. You can pass in an instance of the class in the constructor of this class.
i tried this but now i can't add VerifyAccount to my websocket server (wssv.AddWebSocketService<VerifyAccount>("/verify"))
i get CS0310
I'm not familiar with this library, but I think you could do it like this:
Use the initlizer action to set the behavior's login
wssv.AddWebSocketService<VerifyAccount>("/verify", (b) => b.SetLogin(login));