All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
C#中多维数组的使用

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/11 9:19:22 Browse times: 276 Comment times: 0

C#中多维数组的使用


Head photo

Go homepage
Upload pictures
Write articles

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





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.