C# 如何在T没有任何嵌套元素的列表上使用LINQ?
鉴于以下情况:C# 如何在T没有任何嵌套元素的列表上使用LINQ?,c#,linq,C#,Linq,鉴于以下情况: List<int> foo = new List<int>() { 1, 2, 3, 5, 3, 1 }; class Roo { public int id { get; set; } public string name { get; set; } public Roo() { } } ..... List<Roo> foo = new List<Roo>() { ... }; foo.Any( bar =&g
List<int> foo = new List<int>() { 1, 2, 3, 5, 3, 1 };
class Roo {
public int id { get; set; }
public string name { get; set; }
public Roo() { }
}
.....
List<Roo> foo = new List<Roo>() { ... };
foo.Any( bar => bar.id == 3; )
我在……方面遇到了麻烦。。。我习惯于使用LINQ的部分,其中bar是具有嵌套元素的对象,如下所示:
List<int> foo = new List<int>() { 1, 2, 3, 5, 3, 1 };
class Roo {
public int id { get; set; }
public string name { get; set; }
public Roo() { }
}
.....
List<Roo> foo = new List<Roo>() { ... };
foo.Any( bar => bar.id == 3; )
bar直接为基本类型:
foo.Any( bar => bar > 1);
将LINQ扩展方法视为循环:
对于对象:
foreach(Roo bar in foo)
{
}
我想这会让你更轻松。简单吗?或者foo.Anybar=>bar;哇,我想得太多了。谢谢:@RonKlein我正在关注OP对类和变量的命名。