What would be the best way to have 3 values stored for every element in a 20 element sized array? E.g. An array of 20 people, which can store their name, address and phone number.
Would it be along the lines of
int[][] myArray = new int[20][3];
or something similar?
Thanks
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 more dynamic way of having different count of persons in list. Not a static number. Doing it this style will be much more elastic, because you can add new fields to class and access fields by list[i].Name
instead of array[i][1]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments