答案 0 :(得分:2)
您需要创建一个包含所有上述属性的类
public class Sample
{
public string vocabulary { get; set; }
public string meaning { get; set; }
public int number { get; set; }
public int group { get; set; }
}
然后您可以创建 List
类型的 Sample
,
List<Sample> yourList = new List<Sample>();
您可以将项目添加到列表中,如下所示
yourList.Add(new Sample { vocabulary = "massive", meaning = "very big", number = 5, group = 15 });
如果你想要第一个元素
,你可以像以后一样访问它们 var result = yourList[0];
答案 1 :(得分:1)
这是最简单,最好的方法。您需要创建一个新类,然后创建该类的新实例,然后将其添加到列表中,然后使用LINQ来获取数据
void Main()
{
var list = new List<myClass>()
list.Add(new myClass() {
Vocabluary = "Vocabluary ",
Meaning = "meaning",
Number = 1,
Group = 2})
}
public class myClass
{
public string Vocabluary { get; set; }
public string Meaning { get; set; }
public int Number { get; set; }
public int Group { get; set; }
}
答案 2 :(得分:0)
是的......正如Sajeetharan所提到的,通过自定义类,您可以创建任何维度列表。但我不认为你需要考虑C#中的维度...它比这更高级别。
只需创建一个类并将所需内容放入其中......
public class CustomClass{
public string d1;
public int d2;
public string d3;
public string d4;
...
//you can easily create a N dimension class
}
访问并应用它
public void Main(){
List<CustomClass> list = new List<CustomClass>();
CustomClass cc = new CustomClass();
cc.d1 = "v1";
cc.d2 = 0; //v2
list.Add(cc);
//to access it
foreach(CustomClass tmpClass in list)
{
string d1Value = tmpClass.d1;
int d2Value = tmpClass.d2;
}
}