使用c#生成 6维数组(string类型)(每个花括号里都有随机的数值) 并且for循环遍历数组
时间: 2023-06-19 12:03:08 浏览: 86
以下是生成6维数组并使用for循环遍历的C#代码示例:
```csharp
string[, , , , ,] arr = new string[3, 4, 2, 5, 6, 7];
Random rand = new Random();
// 随机初始化数组
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
for (int k = 0; k < 2; k++)
{
for (int l = 0; l < 5; l++)
{
for (int m = 0; m < 6; m++)
{
for (int n = 0; n < 7; n++)
{
arr[i, j, k, l, m, n] = rand.Next().ToString();
}
}
}
}
}
}
// 使用for循环遍历数组
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
for (int k = 0; k < 2; k++)
{
for (int l = 0; l < 5; l++)
{
for (int m = 0; m < 6; m++)
{
for (int n = 0; n < 7; n++)
{
Console.WriteLine("arr[{0}, {1}, {2}, {3}, {4}, {5}] = {6}", i, j, k, l, m, n, arr[i, j, k, l, m, n]);
}
}
}
}
}
}
```
阅读全文