在网上看到了使用IEnumerator来输出数组.提示错误.哪个朋友我讲讲.感谢!using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] arr = new string[2, 3];
            arr[0,0] = "1,1";
            arr[0,1] = "1,2";
            arr[0,2] = "1,3";
            arr[1,0] = "2,1";
            arr[1,1] = "2,2";
            arr[1,2] = "2,3";
//          foreach (string arrStr in arr)
//           {
//                Console.WriteLine(arrStr);
//            }
//            Console.ReadKey();            IEnumerator ie = arr.GetEnumerator();
            while (ie.MoveNext())
            {
                if (ie != null)
                {
                    Console.WriteLine(ie.Current.ToString());
                }
            }
            Console.ReadKey();
        }
    }
}

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text;
      

  2.   

    arr[0,0] = "1,1";
                arr[0,1] = "1,2";
                arr[0,2] = "1,3";
                arr[1,0] = "2,1";
                arr[1,1] = "2,2";
                arr[1,2] = "2,3";赋值语句右边的逗号是什么意思?
      

  3.   

    你上面的代码我测试过,没有问题啊,另外IEnumerator是接口IEnumerable唯一函数成员GetEnumerator()的返回类型,IEnumerable接口的目的是计你可以该对象使用foreach语句,在.net 2.0以前,你实现IEnumerable接口可能要自己写一个IEnumerator类,现在可以使用yield return语句,比较方便.