Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在T没有任何嵌套元素的列表上使用LINQ?_C#_Linq - Fatal编程技术网

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对类和变量的命名。