我正在研究互联网上已经存在的Squares
扩展方法。我无法得到这个汇编。编译器报告类似"非泛型类型'System.Collections.IEnumerable'不能与类型参数一起使用"。
任何想法下面的代码有什么问题?
任何帮助都非常感谢。
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);
}
}
}
将using System.Collections;
替换为 using System.Collections.Generic;
。