I want to make a collection that stores groups of users. A user can be a member of multiple groups, groups can be nested, a selection of groups should return a distinct IEnumerable<user> .
I could write this from scratch of course using the standard List<T>,Dictionary<T,U> etc collections, but is there a built-in collection that already exposes a lot of this behaviour?
Thanks!
I would do something like this:
Using a
List<T>to hold the users themselves should be fine. Notice that theGroupsproperty of theUsertype is exposed as anIEnumerable<Group>but is implemented internally as aHashSet<Group>to allow you to keep a distinct list as you wanted.