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;
精彩评论