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);
}
}
}
IEnumerable
is a type and not a method and hence has no return type there's a different typeIEnumerable<T>
which is a generic type with one type argument