So I have class Group that contains a list of Users. Every time I try to add a user to the list the compiler alerts me that "Object reference not set to an instance of an object". Can someone help show me where I am going wrong with this. Thanks.
class User{
public string UserName {
get;set;
}
public User(){
}
public User(User u){
UserName = u.UserName;
}
}
class Group{
public string GroupName {
get;set;
}
public List<User> Users {
get;set;
}
public Group(){
}
}
class MainClass
{
public static void Main (string[] args)
{
Group g = new Group ();
g.GroupName = "First Group";
g.Users.Add(new User(){ UserName = "Sam" });
}
}