Let's say I have two lists; Users and Groups.
Users has the following fields: Name, Email, AccessLevel
Groups has the following fields: Name
However, Groups should also contain a list of users (a group is defined with multiple users). So, group "A" could be defined as User 1,2,6,9. These users must be users currently in the users list.
What is the best way to handle this? Can I somehow simply just create references to one of the existing user list items? Or should I create another list within groups which duplicates the information?

1 answers
Well, clearly your Group class needs to have a field of type List<User>.
However, Lists are reference types and so you can assign an existing List<User> object to that field and (as the following 'rough and ready' example shows), when you change that List, the change will automatically be reflected in the Group's List field because they are references to the same object:
answered 2 years ago by:
17279
499
That solves a portion of my problem. However, let's say that I have 10 users and I have 3 groups. These groups are made up of select users from my user list. So my groups look like so: Group1: Users 1,2,3,8 Group2: Users 3,7,10 Group3: Users 1,4,9,10 Now, let's say that I make a change to User 1's access level. I want that change to propagate to my user list in Group 1 and 3 (because User 1 is a member). Make sense? I really want to add a specific user of the list users and maintain the link.
17279
As long as User is a class (not a struct), then any change you make to a User object will be propogated to the user lists of all Groups of which that User is a member. This is because the lists (and hence Groups) contain references to the same User object, not copies of it.
499
Yes, and I see that works as in your example. However, the issue is that I can't seem to selectively add users to a group. I have to add the whole list or none at all. I would like to add users of the list to a group like so... Groups[0].Users = Users[3]; Groups[0].Users= Users[7];
17279
To add users, you'll need to use syntax such as this: Groups[0].Users.Add(Users[3]); Groups[0].Users.Add(Users[7]);
499
Exactly what I needed... thanks!