public MyTest()
{
MyClass a = new MyClass(13, "ab");
MyClass b = new MyClass(24, "cd");
List<MyClass> myList = new List<MyClass>();
myList.Add(a);
myList.Add(b);
//need help here
}
public class MyClass
{
public int fld1 { get; set; }
public string fld2 { get; set; }
public MyClass(int fld1, string fld2)
{
this.fld1 = fld1;
this.fld2 = fld2;
}
}
如何使用lambda表达式获取Mylist
中的fld1集合?预期结果是具有值(13,24)的列表。感谢
答案 0 :(得分:0)
基本的东西,请学习
List<int> result = myList.Select(x=>x.fld1).ToList();