日期:2014-05-18  浏览次数:20814 次

求一LINQ
public class test
{
public int no {get;set;}
public string code {get;set;}
}  


 
var no_1 = new test { no = 1 , code = "1"}
var no_2 = new test { no = 5 , code = "5"}
var no_3 = new test { no = 6 , code = "6"}

List<Test> ts = new List<Test>{no_1 ,no_2,no_3};


求LINQ期望结果(只要其中的一列)

var s = new list<string> { new string{ no = 1 },new string { no = 2 }, new string { no = 3 }}


------解决方案--------------------
var s =ts.Select((x,i)=>(i+1).ToString()).ToList();
------解决方案--------------------
探讨

再加个tolist就完事了

var result = ts.Select(x => x.no).ToList();