zoukankan      html  css  js  c++  java
  • C# Array.CreateInstance创建二维数组及如何遍历二维数组



    1 static void Main(string[] args) 2 { 3 //创建二维数组 4 int[] lengths = {2,3}; 5 int[] lowerBounds = { 1, 10 }; 6 Array arr1 = Array.CreateInstance(typeof(string),lengths,lowerBounds); 7 //给数组赋值 8 arr1.SetValue("", 1, 10); 9 arr1.SetValue("", 1, 11); 10 arr1.SetValue("", 1, 12); 11 arr1.SetValue("", 2, 10); 12 arr1.SetValue("", 2, 11); 13 arr1.SetValue("", 2, 12); 14 //遍历数组 15 System.Collections.IEnumerator arr2 = arr1.GetEnumerator(); 16 int i = 0; 17 int cols = arr1.GetLength(arr1.Rank - 1); 18 while(arr2.MoveNext()){ 19 if (i < cols) 20 { 21 i++; 22 } 23 else { 24 Console.WriteLine(); 25 i = 1; 26 } 27 Console.Write(" {0}",arr2.Current); 28 } 29 Console.WriteLine(); 30 Console.ReadKey(); 31 }

    站在巨人的肩膀上真的会看的更远更清晰!

                               -----用志不分,乃凝于神

  • 相关阅读:
    下拉框插件开发 (一)
    工厂模式 抽象工厂模式
    闭包 构建函数 简单工厂模式
    js继承
    浅谈js观察者模式
    浅谈js单例模式
    localstorage本地存储
    Vi 配置文件
    Vi Command
    我的Firs博客
  • 原文地址:https://www.cnblogs.com/xiong950413/p/9773025.html
Copyright © 2011-2022 走看看