如何声明一个二维数组呢?
怎么对二维数组赋值呢?
如何随机取出其中的值呢?
怎么对二维数组赋值呢?
如何随机取出其中的值呢?
解决方案 »
- 求解: .NET 类型和 SQL Server 类型对应问题.
- C# object byte[] 互相转换
- vs2008 制作windows应用程序 menuStrip怎样在点击后显示或不显示√
- vs2005配置要求
- 求救:通过SqlCommandBuilder对象修改数据库记录失败
- 问:一个主页面是有几个UserControl组成的。当在postUC里发表内容后主页面刷新,可是listUC里的数据却刷新不了,
- 请问如何在使用owc11时单元格合并的性能
- 遍历得到某一格数据
- 寻找与NCTAudio功能类似的语音控件
- 求动态程序页面的程序代码
- 关于C#编写Dll的小问题
- 如何判断自定义公式是否正确?
或
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();
}
}
}
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];
}
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);
可省略数组的大小
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++)
{
}
}
//如何声明一个二维数组呢?
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];