18using System.Collections.Generic;
31 private List<string>
_users =
new List<string>();
45 public string Name {
get; }
66 return _users.Contains(name);
77 if (String.IsNullOrEmpty(name))
79 throw new ArgumentNullException(
"name",
"Must specify a user name to add it to the group.");
117 return (
string)obj ==
Name;
132 return Name.GetHashCode();
151 private List<Group>
_groups =
new List<Group>();
162 List<string> groupNames =
new List<string>();
165 groupNames.Add(group.
Name);
168 return groupNames.ToArray();
180 return _groups.Find(x => x.Equals(name));
192 if (String.IsNullOrEmpty(name))
194 throw new ArgumentNullException(
"name",
"Must specify a group name to add it to the group list.");
198 if (!
_groups.Contains(newGroup))
213 if (
_groups.Contains(existingGroup))
Represents a single group. A group has a name and zero or more users. Users are tracked by name.
bool ContainsUser(string name)
Determine if the specified user is in this group. This is a case- sensitive search.
override int GetHashCode()
Generate a hash code for this instance.
void AddUser(string name)
Add the specified user to this group. If the user is already in the group, the operation is ignored.
string Name
The name of the group (read-only).
List< string > _users
The list of users in this group.
override bool Equals(object? obj)
Override to compare a Group or string to this Group.
void RemoveUser(string name)
Remove a user from this group. If the user is not in the group then the operation is ignored.
Group(string name)
Constructor.
string[] Users
The names of users in this group (read-only).
Represents a list of Groups.
Group? FindGroup(string name)
Retrieve the Group instance for the specified group name.
void RemoveGroup(string name)
Remove the specified group from the list. Operation ignored if the group is not in the list.
List< Group > _groups
The list of groups.
void AddGroup(string name)
Add a group to the list using the given group name. Operation ignored if the group is already in the ...
string[] GroupNames
The names of all groups contained in this list (read-only). The list is always sorted.
The namespace containing all Design Pattern Examples implemented in C#.