【问题标题】:Type `System.Collections.Generic.IEnumerable' does not contain a member `Aggregate' and the best extension method overload类型 `System.Collections.Generic.IEnumerable' 不包含成员 `Aggregate' 和最佳扩展方法重载
【发布时间】:2016-10-29 19:07:06
【问题描述】:

谁能帮我弄清楚我做错了什么

private const long _divisor = // 10^9 - 7
        Enumerable.Repeat(10, 9).Aggregate(1, (p, i) => p * i) - 7;

??

得到错误

键入System.Collections.Generic.IEnumerable' does not contain a memberAggregate' 和最佳扩展方法重载 `System.Linq.Enumerable.Aggregate(这个 System.Collections.Generic.IEnumerable, int, System.Func)' 有一些 无效参数!匿名方法和 lambda 表达式不能 在当前上下文中使用

我觉得我完全按照文档https://msdn.microsoft.com/en-us/library/bb549218(v=vs.110).aspx

【问题讨论】:

  • 您是否遗漏了相关的using 声明?

标签: c# .net linq constants


【解决方案1】:

lambda 表达式不能在当前上下文中使用

您在非原始值上指定const,编译器不允许这样做。

要么删除const 说明符,要么放置一个原始值。

private const long _divisor =  (long)(10e9 - 7); // Or just write 9999999993 instead 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    • 2014-05-24
    • 1970-01-01
    • 2015-02-26
    相关资源
    最近更新 更多