Generic Collections

List<T> (List of T (type))

List<Person> people = new List<Person>();

Person john = new Person() { Name = "John" };
people.Add(john);
people.Add(new Person() { Name = "John" });

Dictonary<K,T> (key, type)

Dictionary<string, Person> dict = new Dictonary <string, Person>();
Person george = new Person() { Name = "George Washington", Age = 67 };
string key = "George"; // Is in wasy better if not identical to the identifier
dict.Add(key, george);

dict.Add("john", new Person() { Name "John Addams", Age = 90 });
dict.Add("tom", new Person() { Name "Thomas Jefferson", Age = 90 });
dict.Add("james", new Person() { Name "James Madison", Age = 90 });

Person secondPresident = dict["john"];
Console.WriteLine($"The second president was: {secondPresident.Name}");

results matching ""

    No results matching ""