c#多维数组

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

 

ExpandedBlockStart.gif 代码
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();
        }
    }

 

 

转载于:https://www.cnblogs.com/Fskjb/archive/2010/05/15/1736359.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值