Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为数组中的所有20个元素存储3个值_C# - Fatal编程技术网

C# 为数组中的所有20个元素存储3个值

C# 为数组中的所有20个元素存储3个值,c#,C#,在20个元素大小的数组中,为每个元素存储3个值的最佳方法是什么?例如,一个20人的数组,可以存储他们的姓名、地址和电话号码 会不会是按照 int[][] myArray = new int[20][3]; 还是类似的 谢谢它应该是一类对象: public class Person { public string Name { get; set; } public string SecondName { get; set; } public string Street {

在20个元素大小的数组中,为每个元素存储3个值的最佳方法是什么?例如,一个20人的数组,可以存储他们的姓名、地址和电话号码

会不会是按照

int[][] myArray = new int[20][3];
还是类似的

谢谢

它应该是一类对象:

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"
 });
公共类人物
{
公共字符串名称{get;set;}
公共字符串SecondName{get;set;}
公共字符串Street{get;set;}
}
List personList=新列表();
personList.Add(新的Person()
{
Name=“Sample”,
SecondName=“S”,
Street=“4825235186”
});

现在,您可以使用更动态的方式在列表中显示不同的人数。不是一个静态数字。这样做会更有弹性,因为您可以通过
list[i].Name
而不是
array[i][1]

使用类的列表向类添加新字段并访问字段