+ 1
C#: Can List<> contain 3 or more parameters?
Like if I need to have id, name and count(n) how many stuff every of it have OR maybe C# have another list-like comands to serve my needs?
5 ответов
+ 1
You should build a class with all of these 3 parameters and create a List of that object type. In my opinion it is a better solution than find a collection with three indexes.
+ 1
DonPietro Cavastano but how can I edit or just search some info in that kind of list? Same example: I created a list of classes and I need to find one man in there
+ 1
Linq - language integrated query allows to create Sql like queries. From System.Linq namespace.
Let's say that your collection is a List<Person> and is called Persons. Where class person have the following properties, Name, Id, Count.
You can use for example Where extension method that comes from the System.Linq which allows you to get elements from the list by certain conditions:
var persons = Persons.Where(p => p.Name == "Tomasz"); // will return all objects from the list that attritbue Name is equal to Tomasz.
For more information I would recommend you to read Msdn about the Linq.
+ 1
Access to the member "name" through the link to the instance is not possible; specify it instead by specifying a type name
Here what I get. How can I solve it? Tomasz
0
Alternatively you can use Tuple<T1,T2,....,Tn>, in your example it would be Tuple<int, string, int>, however DonPietro solution would be much cleaner and more readable.