zoukankan      html  css  js  c++  java
  • 二维数组 规则数组和交叉数组

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication5
    {
    class Program
    {
    static void Main(string[] args)
    {
    #region 严格上的二维数组 12行31列 行列均已经固定
    string[,] ss = new string[12, 31];
    for (int i = 0; i < 12; i++)
    {
    for (int j = 0; j < 31; j++)
    {
    ss[i, j] = i + "_" + j + " " + "";

    }
    }
    for (int i = 0; i < 12; i++)
    {
    for (int j = 0; j < 31; j++)
    {
    Console.Write(ss[i, j]);

    }
    Console.WriteLine();
    }
    #endregion

    #region 交叉数组 行固定 列不固定 每行均是一个一维数组 arr[i]=new string[length]的arr[i]代表一维数组的数组的首地址 new string[length]是为一维数组申请空间
    string[][] arr = new string[5][];

    arr[0] = new string[5];
    arr[0][0] = "0";
    arr[0][1] = "1";
    arr[0][2] = "2";
    arr[0][3] = "3";
    arr[0][4] = "4";

    arr[1] = new string[4];
    arr[1][0] = "0";
    arr[1][1] = "1";
    arr[1][2] = "2";
    arr[1][3] = "3";

    arr[2] = new string[3];
    arr[2][0] = "0";
    arr[2][1] = "1";
    arr[2][2] = "2";


    arr[3] = new string[2];
    arr[3][0] = "0";
    arr[3][1] = "1";


    arr[4] = new string[1];
    arr[4][0] = "0";


    for (int i = 0; i < 5; i++)
    {
    for (int j = 0; j < arr[i].Length; j++)
    {

    Console.WriteLine(string.Format("arr[{0}][{1}]=" + arr[i][j], i, j));
    }
    Console.WriteLine();
    }
    #endregion


    Console.WriteLine("二维数组的hash地址"+arr.GetHashCode());
    for (int i = 0; i < arr.Length; i++)
    {
    Console.WriteLine(string.Format("arr[{0}]的hash地址{1}:",i,arr[i].GetHashCode()) );
    }
    Console.ReadKey();

    }
    }
    }

  • 相关阅读:
    c/cpp枚举练习
    数据类型的标识
    引用变量
    cocos2dx 3.3 笔记
    希望获取到页面中所有的checkbox怎么做?
    如何判断某变量是否为数组数据类型?
    驼峰函数写法
    trim()函数
    js 获取页面可视区域宽高
    全屏滚动插件
  • 原文地址:https://www.cnblogs.com/kexb/p/5089203.html
Copyright © 2011-2022 走看看