Saving 3 values ​​for all 20 elements in an array

What would be the best way to have 3 values ​​for each element in an array of 20 elements? For example. An array of 20 people that can store your name, address and phone number.

Will he line by line

int[][] myArray = new int[20][3];

or something similar?

thanks

+4
source share
1 answer

It should be rather a list of class objects:

public class Person
{
    public string Name { get; set; }
    public string SecondName { get; set; }
    public string Street { get; set; }
}

 List<Person> personList = new List<Person>();
 personList.Add(new Person()
 {
      Name = "Sample",
      SecondName = "S",
      Street = "4825235186"
 });

Now you can have a more dynamic way of having a different number of people on the list. Not a static number. Performing this style will be much more resilient because you can add new fields to the class and access fields list[i].Nameinsteadarray[i][1]

+11
source

Source: https://habr.com/ru/post/1606349/


All Articles