Deadly Nicotine Deadly Nicotine - 1 month ago 7
C# Question

Type `System.Collections.Generic.IEnumerable' does not contain a member `Aggregate' and the best extension method overload

Can someone help me figure out what I'm doing wrong with

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


??

Getting the error


Type
System.Collections.Generic.IEnumerable' does not contain a
member
Aggregate' and the best extension method overload
`System.Linq.Enumerable.Aggregate(this
System.Collections.Generic.IEnumerable, int, System.Func)' has some
invalid arguments !Anonymous methods and lambda expressions cannot be
used in the current context


and I feel like I'm following exactly the documentation https://msdn.microsoft.com/en-us/library/bb549218(v=vs.110).aspx

Answer

lambda expressions cannot be used in the current context

You are specifying const on a non-primitive value, the compiler won't allow it.

Either remove the const specifier or place a primitive value.

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