public override bool Equals(object obj) { Megapolis temp = obj as Megapolis; if (temp == null) { return(false); } return(this.Country.Equals(temp.Country) && (this.City.Equals(temp.City))); }
public static void CitiesinRussia1(List <List <Mesto> > ListOfElements) { Func <Mesto, bool> searchFilter = delegate(Mesto place) { return(place is Megapolis && place.Country == "Россия"); }; Func <Mesto, string> itemToProcess = delegate(Mesto t) { Megapolis m = t as Megapolis; return(m.City); }; for (int i = 0; i < ListOfElements.Count; i++) { var res1 = ListOfElements[i].Where(searchFilter).Select(itemToProcess); foreach (string t in res1) { Console.WriteLine(t); } } }
public static List <Mesto> Generate(int size, List <Mesto> listofelem) //Заполенение коллекции длины size случайными элементами { listofelem = new List <Mesto>(); for (int i = 0; i < size; i++) { int option = rnd.Next(0, 4);//Случайное значение - номер класса элемента который добавляется switch (option) { case 0: Megapolis mp = new Megapolis(); mp.Generate(); Console.WriteLine(mp.ToString()); listofelem.Add(mp); break; case 1: Oblast ob = new Oblast(); ob.Generate(); Console.WriteLine(ob.ToString()); listofelem.Add(ob); break; case 2: Gorod ct = new Gorod(); ct.Generate(); Console.WriteLine(ct.ToString()); listofelem.Add(ct); break; case 3: Address adr = new Address(); adr.Generate(); Console.WriteLine(adr.ToString()); listofelem.Add(adr); break; } } return(listofelem); }