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# C-变换型Linq_C#_Linq - Fatal编程技术网

C# C-变换型Linq

C# C-变换型Linq,c#,linq,C#,Linq,为什么以及如何将'b'b'System.Linq.Enumerable.WhereEnumerableTerator'的类型更改为 'System.Collections.Generic.List' List<int> a = new List<int>{ 45, 78, 45, 12, 4, 78, 54 }; var b = a.Select (n => n +12).Where (n => n>50); //Enumerable.WhereEn

为什么以及如何将'b'b'System.Linq.Enumerable.WhereEnumerableTerator'的类型更改为 'System.Collections.Generic.List'

List<int> a = new List<int>{ 45, 78, 45, 12, 4, 78, 54 };  
var b = a.Select (n => n +12).Where (n => n>50); //Enumerable.WhereEnumerableIterator<int>

b = b.ToList ();  // System.Collections.Generic.List<int>
为什么要改变b型?有可能在C中改变类型吗?例如,是否可以创建“字符串”并将其更改为“字符”的“int”?当然不是。但为什么要更改此代码的类型?

。其中返回IEnumerable。Enumerable.WhereEnumerableTerator是可枚举的具体类。Where用于实现该接口。您不应该在代码中引用它,因为它是一个实现细节,可能会发生更改

.ToList获取IEnumerable并创建具体列表。它不仅仅像你在问题中提到的那样改变类型,它还创建了一个新对象。它是如何实现的,这是您不必担心的另一个实现细节


您可以浏览.NET参考源代码以查看的实现,并且

似乎您正在关注这一点

  var b = a.Where(n => n > 50).Select(n => new
            {
                a = n+12
            }).ToList();

好你为什么写那个代码?你的意图是什么?我不明白。你能重新表述你的问题吗?@atornblad没什么,我只是知道你在这么做。问题是什么?@Dr.Chameleon这很好,但你想实现什么?Selman22是正确的,您已经使用了.ToList