I\'m writing a small code to more understand about property
and static property
. Like these:
class UserIdentity
{
public static
You're trying to assign to a read only static property in an instance constructor. That would cause it to be assigned every time a new instance is created, which would mean it's not read only. You need to assign to it in the static constructor:
public static IDictionary OnlineUsers { get; }
static UserIdentity()
{
OnlineUsers = new Dictionary();
}
Or you can just do it inline:
public static IDictionary OnlineUsers { get; } = new Dictionary();