now*_*ed. 1 .net c# extension-methods .net-4.0
我正在看这个Squares已经存在于Internet中的扩展方法.我无法得到这个编译.编译器报告类似"非泛型类型`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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Med*_*noc 13
替换using System.Collections;为using System.Collections.Generic;.
| 归档时间: |
|
| 查看次数: |
1807 次 |
| 最近记录: |