All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
XML入门教程-XML DHTML 行为_[XML教程]
找出数据库表里重复记录和重复记录数的SQL_[SQL,Server教程]
url传递中文的方法_[Asp.Net教程]
通过继承ConfigurationSection,在web.config中增加自定义配置_[Asp.Net教程]
Ajax 中的高级请求和响应_[AJAX教程]
php,函数GetImageSize_php资料_编程技术
php中rename()函数的妙用_[PHP教程]
Visual,Studio2005发布问题解决办法_.net资料_编程技术
应用技巧:用PHP简易实现中文分词_php资料_编程技术
ASP.NET&Spring.NET&NHibernate最佳实践(三)——第2章环境准备_[Asp.Net教程]
Reading number is top 10 pictures
2012 national geographic daily picture9
壮丽的云彩1
西游四格漫画(六)
超强高考作文
青春清纯美女大集合3
含苞欲放的素颜美少女3
The real super beauty9
The money of more than 100 countries and regions19
The money of more than 100 countries and regions5
Exquisite decoration is not paying too much2
Download software ranking
Boxer Classic video2
Professional killers2 data package
Unix video tutorial19
C#与.NET技术平台实战演练
功夫熊猫2(上集)
XML+Web+Service开发教程
linux高级编程
C#高级编程(第4版)
虚拟机5.5.3版
Boxer's Top ten classic battle9
qq published in(发表于) 2014/7/11 9:18:50 Edit(编辑)
c#中二维数组的使用

c#中二维数组的使用

c#中二维数组的使用

c#中二维数组的使用

需要存储表格式的数据时,可以使用二维数组,图1所示为包括4行3列的二维数组的存储结构。



图1 二维数组的存储结构

* 示例

二维数组的使用

示例中,将用户输入行值和列值作为二维数组的长度,并将数组行索引和列索引相同的数组元素输出为“*”,其他元素输出为“@”。程序代码如下:

Console.Write("请输入定义数组的行数:");

int row = Convert.ToInt32 (Console.ReadLine());

Console.Write("请输入定义数组的列数:");

int col = Convert.ToInt32 (Console.ReadLine());

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

int[,] arr2 = new int[row, col];

Console.WriteLine("结果:");

for (int i = 0; i < row; i++)

{

for (int j = 0; j < col; j++)

{

if (i == j)

{

Console.Write("*");

}

else

{

Console.Write("@");

}

}

Console.WriteLine();

}

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



图2 二维数组示例运行结果图

完整程序代码如下:

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

using System;

using System.Collections.Generic;

using System.Text;

namespace _2

{

class Program

{

static void Main(string[] args)

{

Console.Write("请输入定义数组的行数:");

int row = Convert.ToInt32 (Console.ReadLine());

Console.Write("请输入定义数组的列数:");

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

int col = Convert.ToInt32 (Console.ReadLine());

int[,] arr2 = new int[row, col];

Console.WriteLine("结果:");

for (int i = 0; i < row; i++)

{

for (int j = 0; j < col; j++)

{

if (i == j)

{

Console.Write("*");

}

else

{

Console.Write("@");

}

}

Console.WriteLine();

}

}

}

}




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.