问题
I was looking at this Squares
extension method which was already there in Internet. I could not get this compiling. The compiler reports something like, "The non-generic type `System.Collections.IEnumerable' cannot be used with the type arguments".
any ideas what is wrong with this code below ?
any help is much appreciated.
using System.IO;
using System;
using System.Collections;
static class Program {
static IEnumerable<int> Squares (this int from, int to) {
for (int i=from;i<=to;i++)
{
yield return (int)i*i;
}
}
static void Main(string[] args)
{
var min=1;
foreach (int i in min.Squares(4))
{
Console.WriteLine(i);
}
}
}
回答1:
Replace using System.Collections;
with using System.Collections.Generic;
.
来源:https://stackoverflow.com/questions/19398358/ienumerable-reports-compiler-error-when-used-with-the-namespace-system-collectio