与System.Collections中的命名空间使用时的IEnumerable报道编译器错误 [英] IEnumerable reports compiler error when used with the namespace System.Collections

查看:229
本文介绍了与System.Collections中的命名空间使用时的IEnumerable报道编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这个这是已经存在于互联网广场扩展方法。我不能让这个编译。编译器会报告类似,非泛型类型`System.Collections.IEnumerable不能与类型参数使用

任何想法有什么不对的$ C $低于C?

任何帮助是非常AP preciated。

 使用System.IO;
使用系统;
System.Collections中使用;

静态类节目{

     静态的IEnumerable< INT>平方(这从INT,INT到){
        对于(INT I =距离; I< =来;我++)
        {
            收益回报(INT)I * I;
        }
    }

    静态无效的主要(字串[] args)
    {
        变种分钟= 1;
        的foreach(诠释我在min.Squares(4))
        {
            Console.WriteLine(ⅰ);
        }
    }
}
 

解决方案

替换 System.Collections中使用; 使用System.Collections.Generic;

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);
        }
    }
}

解决方案

Replace using System.Collections; with using System.Collections.Generic;.

这篇关于与System.Collections中的命名空间使用时的IEnumerable报道编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆