int数组中的C#字符串数组

int数组中的C#字符串数组,c#,arrays,string,int,C#,Arrays,String,Int,我需要一个数组的整数数组和字符串在C中# 我想不出任何解决这个问题的正确方法。我来到下面这个片段 string[,] items = new string[10, 2]; for(int 1 = 0; i<10; i++){ items[i, 0] = "Item " + i; items[i, 1] = new int[10]; } string[,]items=新字符串[10,2]; 对于(int 1=0;i可以创建元组数组: (string,int[])[] ite

我需要一个
数组
整数数组
字符串
在C中#

我想不出任何解决这个问题的正确方法。我来到下面这个片段

string[,] items = new string[10, 2];
for(int 1 = 0; i<10; i++){
    items[i, 0] = "Item " + i;
    items[i, 1] = new int[10];
}
string[,]items=新字符串[10,2];

对于(int 1=0;i可以创建元组数组:

(string,int[])[] items = new (string,int[])[10];
for(int i = 0; i < items.Length; i++)
 {
 items[i] = ("Item" + i,new int[10]);
 }
为了进一步提高可读性,您可以创建自己的类并创建该类的数组:

class Item
 {
 public string Name {get;set;}
 public int[] Values {get;set;}
 }

可以创建元组数组:

(string,int[])[] items = new (string,int[])[10];
for(int i = 0; i < items.Length; i++)
 {
 items[i] = ("Item" + i,new int[10]);
 }
为了进一步提高可读性,您可以创建自己的类并创建该类的数组:

class Item
 {
 public string Name {get;set;}
 public int[] Values {get;set;}
 }

您可以创建这样的类

公共类测试
{
公共字符串名称{get;set;}
公共int[]数组{get;set;}
}
List testList=newlist();
对于(int i=0;i<4;i++)
{
测试=新测试
{
Name=“第1项”,
数组=新整数[6]
};
对于(int j=0;j<6;j++)
{
测试数组[j]=j+1;
}
testList.Add(test);
}
foreach(testList中的var项)
{
Console.Write(item.Name);
foreach(item.Array中的var arr)
{
控制台。写入(“\t”+arr);
}
Console.WriteLine();
}
结果

Item 1  1       2       3       4       5       6
Item 1  1       2       3       4       5       6
Item 1  1       2       3       4       5       6
Item 1  1       2       3       4       5       6


您可以创建这样的类

公共类测试
{
公共字符串名称{get;set;}
公共int[]数组{get;set;}
}
List testList=newlist();
对于(int i=0;i<4;i++)
{
测试=新测试
{
Name=“第1项”,
数组=新整数[6]
};
对于(int j=0;j<6;j++)
{
测试数组[j]=j+1;
}
testList.Add(test);
}
foreach(testList中的var项)
{
Console.Write(item.Name);
foreach(item.Array中的var arr)
{
控制台。写入(“\t”+arr);
}
Console.WriteLine();
}
结果

Item 1  1       2       3       4       5       6
Item 1  1       2       3       4       5       6
Item 1  1       2       3       4       5       6
Item 1  1       2       3       4       5       6

使用字典

Dictionary<string, int[]> myDictionary = new Dictionary<string, int[]>();

// Add Item:
myDictionary.Add("Item 1", new int[]{1,2,3,4,5,6});
使用字典

Dictionary<string, int[]> myDictionary = new Dictionary<string, int[]>();

// Add Item:
myDictionary.Add("Item 1", new int[]{1,2,3,4,5,6});

您还可以命名元组的各个部分
var items=new(string name,int[]Values)[10];
您还可以命名元组的各个部分
var items=new(string name,int[]Values)[10];
为什么不使用结构而不是类?为什么不使用结构而不是类?还可以使用string和int[]还可以使用string和int[]属性定义您自己的类。