c#多维数组

 多维数组并不常用,我觉得倒不如用xml还好

 

代码
class ArrayTest
    {

        
public void TestArray(){    
       

          
//写法一:
            
//String[, ,] items = new String[,,] { 
            
//    { 
            
//        { "A1", "A2", "A3", "A4", "A5" }, 
            
//        { "B1", "B2", "B3", "B4", "B5" }, 
            
//        { "C1", "C2", "C3", "C4", "C5" }, 
            
//        { "D1", "D2", "D3", "D4", "D5" }
            
//    },
            
//    { 
            
//        { "E1", "E2", "E3", "E4", "E5" }, 
            
//        { "F1", "F2", "F3", "F4", "F5" }, 
            
//        { "G1", "G2", "G3", "G4", "G5" },
            
//        { "H1", "H2", "H3", "H4", "H5" }
            
//    }
            
//};

            
//写法二:
            
//String[, ,] items ={ 
            
//    { 
            
//        { "A1", "A2", "A3", "A4", "A5" }, 
            
//        { "B1", "B2", "B3", "B4", "B5" }, 
            
//        { "C1", "C2", "C3", "C4", "C5" }, 
            
//        { "D1", "D2", "D3", "D4", "D5" }
            
//    },
            
//    { 
            
//        { "E1", "E2", "E3", "E4", "E5" }, 
            
//        { "F1", "F2", "F3", "F4", "F5" }, 
            
//        { "G1", "G2", "G3", "G4", "G5" },
            
//        { "H1", "H2", "H3", "H4", "H5" }
            
//    }
            
//};

            
//写法三:
            String[, ,] items = new String[2,4,5]{ 
                { 
                    { 
"A1""A2""A3""A4""A5" }, 
                    { 
"B1""B2""B3""B4""B5" }, 
                    { 
"C1""C2""C3""C4""C5" }, 
                    { 
"D1""D2""D3""D4""D5" }
                },
                { 
                    { 
"E1""E2""E3""E4""E5" }, 
                    { 
"F1""F2""F3""F4""F5" }, 
                    { 
"G1""G2""G3""G4""G5" },
                    { 
"H1""H2""H3""H4""H5" }
                }
            };

            Console.WriteLine(items.Rank);
//输出3,rank从1开始计数,但表示某一个秩(维度)从下标0开始
            
            Console.WriteLine(
"items.GetUpperBound(0)="+items.GetUpperBound(0));//输出1
            Console.WriteLine("items.GetUpperBound(1)=" + items.GetUpperBound(1));//输出3
            Console.WriteLine("items.GetUpperBound(2)=" + items.GetUpperBound(2));//输出4        


            Console.WriteLine(
"items.GetLowerBound(0)=" + items.GetLowerBound(0));//输出0
            Console.WriteLine("items.GetLowerBound(1)=" + items.GetLowerBound(1));//输出0
            Console.WriteLine("items.GetLowerBound(2)=" + items.GetLowerBound(2));//输出0

            Console.WriteLine(
"遍历输出");
            
for (int i = 0; i < items.Rank; i++)
            {
                Console.WriteLine(
"items.GetUpperBound(" + i + ")=" + items.GetUpperBound(i));
                Console.WriteLine(
"items.GetLowerBound(" + i + ")=" + items.GetLowerBound(i));                
            }

            
for (int i = items.GetLowerBound(0); i <= items.GetUpperBound(0); i++)
            {
                
for (int j = items.GetLowerBound(1); j <= items.GetUpperBound(1);j++ )
                {
                    
for (int k = items.GetLowerBound(2); k <=items.GetUpperBound(2);k++ )
                    {
                        Console.Write(items[i,j,k]
+" ");                        
                    }
                    Console.WriteLine();
                } 
            }          

            Console.WriteLine(
"数组中元素的总数目(length):"+items.Length);          
            Console.ReadLine();
        }
    }

 

 

posted @ 2010-05-15 19:10  Fskjb  阅读(923)  评论(0编辑  收藏  举报
年年行好运