Suppose there is a class
public class Information { public string Name; public string Surname; public int Age; } There is another class:
public class InfoByCities { public List<InFormation> Moscow; public List<InFormation> Saint_Petersburg; public List<InFormation> Rostov; } Fill in this List<> :
InfoByCities fill = new InfoByCities(); int Amount = 1500; fill.Moscow = new List<Information>(Amount); for (int i = 0; i < Amount; i++) { Information inf = new Information(); inf.Name = "Саша"+ i.ToString(); inf.Surname = "Поляков" + i.ToString(); inf.Age = i; fill.Moscow.Add(inf); } fill.Saint_Petersburg = new List<Information>(Amount); for (int i = 0; i < Amount; i++) { Information inf = new Information(); inf.Name = "Пётр" + i.ToString(); inf.Surname = "Поляков" + i.ToString(); inf.Age = i; fill.Saint_Petersburg.Add(inf); } fill.Rostov = new List<Information>(Amount); for (int i = 0; i < Amount; i++) { Information inf = new Information(); inf.Name = "Саша" + i.ToString(); inf.Surname = "Петухов" + i.ToString(); inf.Age = i; fill.Rostov.Add(inf); } Question: How can I implement a search in all List<> without referring to each individually. For example, find on all three lists of people with the name "Sasha". The number of List<> can be much larger.
Listentities. How do you even see the search in the collection without referring to it directly? And you have all three entities have the same type, therefore, you can search in any of the lists equally. In my opinion, it may look like this: a) We make a list of lists (that is, a container where the variablesMoscow,Saint_Petersburg,Rostovand others will be stored). And now we do the search already there, sorting through the contents of each variable. Either b) - you can make 1 list for the searchList<InFormation> Search, where we add the contents of all sheets and search. - BlackWitcherInformationwould be one, but in theInformationclass itself add aCityfield, for example. And you have a typo in the code - compare:InFormationandInformation. - BlackWitcherList(search O (n)) useHashSet(search O (1)), orSortedList(search O (log n)). See also sentinel value . Well, you can try parallelizing the search. - Alexander Petrov