18using System.Collections.Generic;
40 public string Name {
get; }
47 public override bool Equals(
object? obj)
57 return (
string)obj ==
Name;
73 return Name.GetHashCode();
92 List<User>
_users =
new List<User>();
102 List<string> userNames =
new List<string>();
105 userNames.Add(user.
Name);
108 return userNames.ToArray();
120 return _users.Find(x => x.Equals(
new User(name)));
132 if (String.IsNullOrEmpty(name))
134 throw new ArgumentNullException(
"name",
"Must specify a user name to add it to the user list.");
138 if (!
_users.Contains(newUser))
153 if (
_users.Contains(existingUser))
155 _users.Remove(existingUser);
Represents a user with a name.
User(string name)
Constructor.
override int GetHashCode()
Generate a hash code for this instance.
string Name
The name of the user (read-only).
override bool Equals(object? obj)
Override to compare a User or string to this User.
Represents a list of users.
User? FindUser(string name)
Retrieve the User instance for the specified user name.
void AddUser(string name)
Add the specified user name as a user. Operation ignored if user is already in the list.
void RemoveUser(string name)
Remove the specified user name as a user. Operation ignored if user is not in the list.
List< User > _users
The list of users.
string[] UserNames
The user names contained in this list (read-only). The list is always sorted.
The namespace containing all Design Pattern Examples implemented in C#.