One option would be to create a singleton class to represent the logged on user. You can then access the one and only instance of that class anywhere in the app. Here's a simple example of such a class that could be used in this case:
internal class CurrentUser
{
private static CurrentUser _instance;
public static CurrentUser Instance
{
get
{
if (_instance == null)
{
_instance = new CurrentUser();
}
return _instance;
}
}
public string UserName { get; set; }
private CurrentUser()
{
}
}
You can use:
C#:
CurrentUser.Instance.UserName
to get and set the user name of the current user anywhere in your code.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.