c# 可变二维数组_C#| 具有固定行大小和可变列大小的二维数组
生活随笔
收集整理的這篇文章主要介紹了
c# 可变二维数组_C#| 具有固定行大小和可变列大小的二维数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
c# 可變二維數組
Here, the task is to declare a two dimensional array – where number rows are given and columns are variable length:
在這里,任務是聲明一個二維數組-其中給出了行數,列數是可變長度 :
To declare such array, we use the following syntax:
為了聲明這樣的數組,我們使用以下語法:
int[][] jag = new int[3][];To assign rows values with variable length, we use following syntax:
要分配具有可變長度的行值,我們使用以下語法:
jag[0] = new int[] { 12, 34, 5, 6, 7 };jag[1] = new int[] { 15, 52 };jag[2] = new int[] { 1, 2, 3 };Program:
程序:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace Array3 {class Program{static void Main(string[] args){int[][] jag = new int[3][];jag[0] = new int[] { 12, 34, 5, 6, 7 };jag[1] = new int[] { 15, 52 };jag[2] = new int[] { 1, 2, 3 };for(int i=0;i<3;i++){for(int j=0;j<jag[i].Length;j++){Console.Write("{0}\t", jag[i][j]);}Console.WriteLine();}Console.ReadKey();}} }Output
輸出量
12 34 5 6 7 15 52 1 2 3翻譯自: https://www.includehelp.com/dot-net/two-dimensional-array-with-fixed-row-size-and-variable-columns-size.aspx
c# 可變二維數組
總結
以上是生活随笔為你收集整理的c# 可变二维数组_C#| 具有固定行大小和可变列大小的二维数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配一副近视眼镜多少钱啊?
- 下一篇: c#数组获取元素的索引_获取元素集合