LINQ查询索引

List<Person> People = new List<Person>
{
   new Person { ID = 33, Name = "lyf"},
   new Person { ID = 22, Name = "azw"}
};

var query = People.Select((person, index) => new { index, person.Name }).OrderBy(itm =>itm.Name);
foreach (var item in query)
{
   Response.Write(item.index.ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;" + item.Name + "<br/>");
}

 

 

public class Person
{
public int ID { get; set; }

public string Name { get; set; }
}

posted @ 2013-01-19 15:39  yellowshorts  阅读(1843)  评论(0编辑  收藏  举报