繁体   English   中英

C#取算符

[英]C# Take operator

给出以下声明

int[] numbers = { 0, 1, 2, 3 };

我注意到.NET 4.6.1上的VS 2015允许以下内容采用前三个数字

IEnumerable<int> firstThree = System.Linq.Enumerable.Take(numbers, 3);

但是,它不允许以下情况

IEnumerable<int> firstThree = numbers.Take(3);

我是C#的新手,无法理解为什么无法将调用解析为扩展方法。

Take是一个扩展方法,可以在名称空间 System.Linq下找到。

您只需要在文件中包含该名称空间即可:

using System.Linq;

然后您将可以使用扩展方法。

您错过添加吗

using System.Linq;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM