I have class:
static class GetRole
{
public static string OfUser(string username)
{
string result="None";
foreach (string key in WebConfigurationManager.AppSettings)
{
if (WebConfigurationManager.AppSettings[key].Contains(username))
{
result = WebConfigurationManager.AppSettings[key];
break;
}
}
return result;
}
}
i would like to use it lik ethis
string role = GetRole.OfUser(username);
or like this even better:
string role = GetRole(username);
how do i do this?
So do so; that appears to be correct. Did you try it?
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 GetRoleinside 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.