创建下限非零数组

lowerBounds {2005,1}  表示 一个二维的 下限 是 2005 跟1 开始,

lengths {5,4} 表示

  2005 维数增长4个  也就是 2005-2009 ,

  1      维数增长4个  也就是 1-4

      然后通过 Array.CreateInstance 创建二维数组。 如下代码

    

      public static void NoZeroArray()
        {
            int[] lowerBounds = { 2005, 1 };
            int[] lengths = { 5, 4 };

            decimal[,] quarterlyRevenue = (decimal[,])Array.CreateInstance(typeof(decimal), lengths, lowerBounds);

            Console.WriteLine("{0,4} {1,9} {2,9} {3,9} {4,9}", "Year", "Q1", "Q2", "Q3", "Q4");

            int firstYear = quarterlyRevenue.GetLowerBound(0);
            int lastYear = quarterlyRevenue.GetUpperBound(0);
            int firstQuarter = quarterlyRevenue.GetLowerBound(1);
            int lastQuarter = quarterlyRevenue.GetUpperBound(1);

            for (int year = firstYear; year <= lastYear; year++)
            {
                Console.Write(year + " ");
                for (int quarter = firstQuarter; quarter <= lastQuarter; quarter++)
                {
                    Console.Write("{0,9:C} ", quarterlyRevenue[year, quarter]);
                }
                Console.WriteLine();
            }
 
        }

//1维0基数组
Array a = Array.CreateInstance(typeof(string), new int[] { 0 }, new int[]{0});
//1维1基数据
Array a1 = Array.CreateInstance(typeof(string), new int[] { 0 }, new int[] { 0 });

//2维0基数组
Array a2 = new string[0, 0];

//2维0基数组
Array a3 = Array.CreateInstance(typeof(string), new int[] { 0, 0 }, new int[] { 0, 0 });
//2维1基数据
Array a4 = Array.CreateInstance(typeof(string), new int[] { 0, 0 }, new int[] { 1, 1 });

原文地址:https://www.cnblogs.com/dragon-L/p/5370205.html