书中写到:如果要迭代一个类成员,例如一个方法。则使用IEnumerable。        public static IEnumerable SimpleList()
        {
            yield return "string 1";
            yield return "string 2";
            yield return "string 3";
        }
        static void Main(string[] args)
        {
            foreach (string item in SimpleList())
                Console.WriteLine(item);
            Console.ReadKey();        }求助

解决方案 »

  1.   

    你的代码没有错,是不是命名冲突了,有 IEnumerable 的命名空间?
      

  2.   

    using System.Collections;这个命名空间已经引用了。
      

  3.   

    你用的2003吗?我用的2005里面提示错误是:错误 9 使用泛型 类型“System.Collections.Generic.IEnumerable<T>”需要“1”个类型参数
    是不是缺少泛型的参数!
      

  4.   

    刚才我又测试下。没有问题了。可能是当时代码较乱。练习IEnumerable 还写了几处代码中有错误导致的吧。
    谢谢晓月大哥与amandag 
      

  5.   

    这样:
    public static IEnumerable<***> SimpleList()