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();

    }
    }
    }

  • 相关阅读:
    21.错误和异常
    20.装饰器相关
    19.装饰器
    18.函数编程的练习
    Remove Duplicates from Sorted List II
    Ubuntu 12.04输入密码登陆后又跳回到登录界面
    Remove Linked List Elements
    Populating Next Right Pointers in Each Node *
    Convert Sorted Array to Binary Search Tree
    Flatten Binary Tree to Linked List *
  • 原文地址:https://www.cnblogs.com/kexb/p/5089203.html
Copyright © 2011-2022 走看看