Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)qq
published in(发表于) 2014/7/11 9:19:22
C#中多维数组的使用

C#中多维数组的使用

C#中多维数组的使用

在多维数组中,最常使用的是二维数组,其次是三维数组。下面以三维数组为例对多维数组的创建及读取作简单介绍。

* 示例

多维数组的使用

示例将定义一个三维数组,并使用foreach语句将该数组输出。程序代码如下:

static void Main(string[] args)

{

//声明一个三维数组

int[, ,] arr3;

//初始化该三维数组

arr3 = new int[,,] { { { 1, 2, 3 } }, { { 4, 5, 6 } } };

//本教程来自网站源代码http://www.isstudy.com

//使用foreach语句遍历数组并输出

foreach (int i in arr3)

{

Console.WriteLine(i);

}

}

键运行程序,运行结果如图1所示。



图1 三维数组示例运行结果图

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Text;

namespace _3

{

class Program

{

static void Main(string[] args)

{

//声明一个三维数组

int[, ,] arr3;

//初始化该三维数组

arr3 = new int[,,] { { { 1, 2, 3 } }, { { 4, 5, 6 } } };

//使用foreach语句遍历数组并输出

//本教程来自网站源代码
http://www.isstudy.com

foreach (int i in arr3)

{

Console.WriteLine(i);

}

}

}

}




If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759