Answer the question
In order to leave comments, you need to log in
How to add an element to a multidimensional list?
I have this code:
List<List<string>> Users = new List<List<string>>()
{
new List<string> {"*", "*", "*", "1.22.2002", "34", "24", "152"},
new List<string> {"*", "*", "*", "17.08.2004", "24", "2234", "1888"},
new List<string> {"*", "*", "*", "3.1.2000", "24", "34", "352"},
new List<string> {"*", "*", "*", "4.7.1999", "224", "234", "1452"},
};
Answer the question
In order to leave comments, you need to log in
This is not a multidimensional list, but a list of lists. So just through Add, and into the nested list - through Users[НомерСтроки].Add()
But judging by your code, you need not a list of lists, but a list of concrete classes.
public class User
{
public string FirstName {get; set;}
public string LastName {get; set;}
public string Patronymic {get; set;}
public DateTime DateOfBirth {get; set;}
// ... всё остальное
}
var users = new List<User> {
new User { DateOfBirth = new DateTime(1999, 07, 04) },
new User { DateOfBirth = new DateTime(2000, 01, 03) },
// итд
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question