我对LINQ很陌生,我有以下脚本,如果条件满足,该脚本将表中的第一项返回给我,但是,我希望获得所有不同的项,而不仅仅是第一个。我在这个平台上还比较陌生。
public LG GetLG (int WID)
{
lock (locker) {
return database.Table<LG> ().FirstOrDefault (x => x.id == WID);
}
}
是.Distinct()
你在找什么?
return database.Table<LG>.Where(x => x.id == WID).Distinct()
以下链接包含有用的材料:
例子:
List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };
IEnumerable<int> distinctAges = ages.Distinct();
Console.WriteLine("Distinct ages:");
foreach (int age in distinctAges)
{
Console.WriteLine(age);
}
此代码产生以下输出:
年龄段:
21
46
55
17
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句