【发布时间】:2016-12-19 16:40:29
【问题描述】:
我有这门课
class Test
{
public string Property { get; set; }
public string ID { get; set; }
public List<string> MyProperty { get; set; }
}
我创建了它的一个实例
List<Test> t = new List<Test>() {
new Test() {
ID = "1",
Property = "2"
},
new Test() {
ID = "2",
Property = "3"
},
new Test() {
ID = "2",
Property = "5"
}
};
我想要一个列表,其中包含按 ID 过滤的不同元素以及 public List MyProperty { get;放; } 应填写 public string Property { get;放; } 数据。
所以最终的结果应该是
List<Test> = {
1. ID = "1",List<MyProperty> = "2"
2. ID = "2",List<MyProperty> = "2"
};
【问题讨论】:
-
List<MyProperty>你的意思是List<string> MyPropertyList吗?您不能使用变量的名称作为类型。