N
N
NeoShima2020-10-05 14:40:07
Fonts
NeoShima, 2020-10-05 14:40:07

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"},
            };


How can I add values ​​to this list that the user enters? PS I am a noob at c#

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-10-05
@vabka

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) },
  // итд
};

F
freeExec, 2020-10-05
@freeExec

AddThe and methods Insertadd and insert a value into the list. Reading the documentation is helpful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question