/ / IEnumerableは、名前空間System.Collections - c#、.net、.net-4.0、extension-methodsで使用するとコンパイルエラーを報告します。

IEnumerableは、名前空間System.Collections - c#、.net、.net-4.0、extension-methodsで使用するとコンパイルエラーを報告します。

私はこれを見ていた 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);
}
}
}

回答:

回答№1の13

置換 using System.Collections; 〜と using System.Collections.Generic;.