开发者

Get and order all elements from list of objects?

Just want to display all the int elements prodId1 from a list of objects in ascendi开发者_JAVA技巧ng order. Aware of the order by function but not sure the easiest way to do so.


List<object> listOfObjects = { 1, "2", new object(), 3, 4, "5" };
IEnumerable<int> orderedInts = listOfObjects .OfType<int>().OrderBy(i => i);


Suppose the name of the list is "list" :

IEnumerable<int> orderedListInts = list.OfType<int>().OrderBy(i => i);


I'm guessing you have a list of objects (say of type MyRecord> with a Property ProdId1, and you want these values.

IList<MyRecord> list;
IEnumerable<int> ids = from item in list 
    orderby item.ProdId1 
    select item.ProdId1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜