[Solved] how do i use a class without instantiating it?


i would like to use it like this

string role = GetRole.OfUser(username);

So do so; that appears to be correct. Did you try it?

or like this even better:

string role = GetRole(username);

That won’t work; you have to specify the method you’re calling as well as what class it comes from.

If you had a static void GetRole inside the same class as the code that you’re calling it from, then you could do that.


However, just because you can do something doesn’t mean you should. The natural way to do “get the role of a user” is to call a method that belongs to the user itself. That in turn implies having a User class which you instantiate for each user.

solved how do i use a class without instantiating it?