static void UseCustomIndexer() { PersonCollection myPeople = new PersonCollection(); myPeople[0] = new Person("Homer", "Simpson", 40); myPeople[1] = new Person("Marge", "Simpson", 38); for (int i = 0; i < myPeople.Count; i++) { Console.WriteLine("Person number: {0}", i); Console.WriteLine("Name {0} {1}", myPeople[i].FirstName, myPeople[i].LastName); Console.WriteLine("Age: {0}", myPeople[i].Age); Console.WriteLine(); } }
private static void UseCustomCollection() { PersonCollection myPeople = new PersonCollection(); myPeople[0] = new Person("Homer", "Simpson", 40); myPeople[1] = new Person("Marge", "Simpson", 38); myPeople[2] = new Person("Lisa", "Simpson", 9); myPeople[3] = new Person("Bart", "Simpson", 7); myPeople[4] = new Person("Maggie", "Simpson", 2); for (int i = 0; i < myPeople.Count; i++) { Console.WriteLine("Person #{0}", i); Console.WriteLine("Name: {0} {1}", myPeople[i].FirstName, myPeople[i].LastName); Console.WriteLine("Age: {0}", myPeople[i].Age); Console.WriteLine(); } }
private static void Main(string[] args) { Console.WriteLine("***** Fun with Indexers *****\n"); var myPeople = new PersonCollection(); myPeople["Homer"] = new Person("Homer", "Simpson", 40); myPeople["Marge"] = new Person("Marge", "Simpson", 38); var homer = myPeople["Homer"]; Console.WriteLine(homer.Name + " " + homer.Surname + " " + homer.Age); //UseGenericListOfPeople(); MultiIndexerWithDataTable(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Indexers *****\n"); PersonCollection myPeople = new PersonCollection(); //add objects w indexer sytnax myPeople[0] = new Person("Homer", "Simpson", 40); myPeople[1] = new Person("Marge", "Simpson", 38); myPeople[2] = new Person("Lisa", "Simpson", 9); myPeople[3] = new Person("Bart", "Simpson", 7); myPeople[4] = new Person("Maggie", "Simpson", 2); //obtain and display each item w indexer for (int i = 0; i < myPeople.Count; i++) { Console.WriteLine("Person number: {0}", i); Console.WriteLine("Name: {0} {1}", myPeople[i].);
public static void Main() { Console.Title = "Пример создания индексатора"; Console.ForegroundColor = ConsoleColor.Green; var people = new PersonCollection { [0] = new Person("Artem", "Muratov", 30), [1] = new Person("Gena", "Acrabatov", 27), [2] = new Person("Leonid", "Filatov", 50), [3] = new Person("Oleg", "Penetratov", 18) }; for (var i = 0; i < people.Count; i++) { Console.Write($"Номер лица: {i} "); Console.WriteLine($"Фамилия: {people[i].LastName}, Имя: {people[i].FirstName}, Возраст: {people[i].Age}"); } MultiIndexer(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Indexers *****\n"); PersonCollection myPeople = new PersonCollection(); myPeople["Sergeo"] = new Person("Sergeo", "Next", 45); myPeople["Vika"] = new Person("Vika", "Next", 39); myPeople["Vova"] = new Person("Vova", "Tourtsev", 17); myPeople["Alan"] = new Person("Alan", "???", 18); //foreach (Person person in myPeople) //{ Person person = myPeople["Vova"]; //Console.WriteLine("Person number: {0}", i); // номер лица //Console.WriteLine("Name: {0} {1}", // person.FirstName, person.LastName); // имя и фамилия //Console.WriteLine("Age: {0}", person.Age); // возраст Console.WriteLine(person.ToString()); //} Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Indexers *****\n"); PersonCollection myPeople = new PersonCollection(); // Add objects with indexer syntax. myPeople[0] = new Person("Homer", "Simpson", 40); myPeople[1] = new Person("Marge", "Simpson", 38); myPeople[2] = new Person("Lisa", "Simpson", 9); myPeople[3] = new Person("Bart", "Simpson", 7); myPeople[4] = new Person("Maggie", "Simpson", 2); // Now obtain and display each item using indexer. for (int i = 0; i < myPeople.Count; i++) { Console.WriteLine("Person number: {0}", i); Console.WriteLine("Name: {0} {1}", myPeople[i].FirstName, myPeople[i].LastName); Console.WriteLine("Age: {0}", myPeople[i].Age); Console.WriteLine(); } }
static void Main( string[] args ) { Console.WriteLine("***** Fun with Indexers *****\n"); PersonCollection myPeople = new PersonCollection(); // Add objects with indexer syntax. myPeople[0] = new Person("Homer", "Simpson", 40); myPeople[1] = new Person("Marge", "Simpson", 38); myPeople[2] = new Person("Lisa", "Simpson", 9); myPeople[3] = new Person("Bart", "Simpson", 7); myPeople[4] = new Person("Maggie", "Simpson", 2); // Now obtain and display each item using indexer. for (int i = 0; i < myPeople.Count; i++) { Console.WriteLine("Person number: {0}", i); Console.WriteLine("Name: {0} {1}", myPeople[i].FirstName, myPeople[i].LastName); Console.WriteLine("Age: {0}", myPeople[i].Age); Console.WriteLine(); } }
static void SimpleIndexing() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("=> Simple Indexer"); PersonCollection people = new PersonCollection(); people[0] = new Person("Homer", "Simpson", 40); people[1] = new Person("Marge", "Simpson", 38); people[1] = new Person("Lisa", "Simpson", 9); people[3] = new Person("Bart", "Simpson", 7); people[4] = new Person("Maggie", "Simpson", 2); for (int i = 0; i < people.Count; i++) { Console.WriteLine($"Person Number: {i}, Name: {people[i].FirstName} {people[i].LastName}, Age: {people[i].Age}"); } foreach (Person p in people) { Console.WriteLine($"Person Name: {p.FirstName} {p.LastName}, Age: {p.Age}"); } }
static void Main(string[] args) { Console.WriteLine("**** Fun with Indexers ****"); PersonCollection myPeople = new PersonCollection(); //add objects with indexers syntax myPeople[0] = new Person("Homer", "Simpson", 40); myPeople[1] = new Person("Marge", "Simpson", 38); myPeople[2] = new Person("Lisa", "Simpson", 9); myPeople[3] = new Person("Bart", "Simpson", 7); myPeople[4] = new Person("Maggie", "Simpson", 2); //Now obtain and display each item using indexer. for (int i = 0; i < myPeople.Count; i++) { Console.WriteLine($"Person number {i}"); Console.WriteLine($"Name: {myPeople[i].FirstName} {myPeople[i].LastName}"); Console.WriteLine($"Age: {myPeople[i].Age}"); } Console.WriteLine("**** Using List of People****"); UseGenericListOfPeople(); Console.Read(); }