LINQ查询从对象列表返回不同的字段值 [英] linq query to return distinct field values from a list of objects

查看:102
本文介绍了LINQ查询从对象列表返回不同的字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 类OBJ 
{
INT TYPEID; // 10种0-9
串uniqueString; //这是唯一的
}



假设有清单,obj的100个元素,但只有10个独特的typeIDs。结果
是有可能做写LINQ查询从OBJ文件?


解决方案列表返回10个独特的整数

  objList.Select(O = GT; o.typeId).Distinct()


class obj
{
int typeID; //10 types  0-9 
string uniqueString; //this is unique
}

Assume there is list with 100 elements of obj, but only 10 unique typeIDs.
Is it possible to do write a LINQ query return the 10 unique ints from the list of objs?

解决方案

objList.Select(o=>o.typeId).Distinct()

这篇关于LINQ查询从对象列表返回不同的字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆