二维数组的问题~~

yinsuxia 2010-10-13 03:32:04
如何声明一个二维数组呢?
怎么对二维数组赋值呢?
如何随机取出其中的值呢?
...全文
106 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoujk 2010-10-13
  • 打赏
  • 举报
回复

//如何声明一个二维数组呢?
int a = 10, b = 20;
int [,] aSS = new int [a,b];
//怎么对二维数组赋值呢?
for(int j = 0; j < b; j ++)
{
for(int i = 0;i < a;i ++)
{
aSS [i,j] = 10;
}
}
//如何随机取出其中的值呢?
//把 i,j 分别取随机数,范围分别是 0~a-1 和 0~b-1;然后
int xxx = aSS[i,j];

wuyq11 2010-10-13
  • 打赏
  • 举报
回复
int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} };
可省略数组的大小
int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} };

for (int i = 0; i < numbers .GetLength(0); i++)
{
for (int j = 0; j < numbers .GetLength(1); j++)
{

}
}
a_110120 2010-10-13
  • 打赏
  • 举报
回复
貌似要随机取值 顶2#
不叫月红 2010-10-13
  • 打赏
  • 举报
回复
int [,] IntArr={{1,2,3,4},{2,3,4,5},{3,4,5,6}};
int row = IntArr.GetLength(0);
int column = IntArr.GetLength(1);
Random ra = new Random();
int i = ra.Next(row);
int j=ra.Next (column);
int aa=IntArr [i,j];
Response.Write(aa);
nigerenz 2010-10-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]
int[,] a2=new int[2,3];

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

C# code

using System;
class Matrix
{
static void Main()
{
int[,] arr=new int[4,6];
for(int i=0;i<4;i++)
……
[/Quote]

顶一楼的
baihualin1983 2010-10-13
  • 打赏
  • 举报
回复
int x = 10;
int y = 10;
int[,] array;
/// <summary>
/// 创建二维数组
/// </summary>
private void create()
{
array = new int[x, y];
}
/// <summary>
/// 给二维数组赋值
/// </summary>
private void setValue()
{
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
array[i, j] = new Random().Next(100);
}
}
}
/// <summary>
/// 随机获取二维数组的值
/// </summary>
private void getValue()
{
int xValue = new Random().Next(x);
int yValue = new Random().Next(y);
int value = array[xValue, yValue];
}
q107770540 2010-10-13
  • 打赏
  • 举报
回复
int[,] a2=new int[2,3];

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

using System;
class Matrix
{
static void Main()
{
int[,] arr=new int[4,6];
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
arr[i,j]=(i+1)*10+j+1;
}
}
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
Console.Write("{0} ",arr[i,j]);
}
Console.WriteLine();
}
}
}

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧