使用c#生成 一个6维数组(为string类型)(每个花括号里都有的值) 并且for循环遍历数组
时间: 2023-06-19 19:03:05 浏览: 73
可以使用以下代码生成6维字符串数组并使用for循环遍历它:
```csharp
string[, , , , ,] myArray = new string[2, 3, 4, 5, 6, 7];
// 填充数组
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 4; k++)
{
for (int l = 0; l < 5; l++)
{
for (int m = 0; m < 6; m++)
{
for (int n = 0; n < 7; n++)
{
myArray[i, j, k, l, m, n] = $"({i}, {j}, {k}, {l}, {m}, {n})";
}
}
}
}
}
}
// 遍历数组
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 4; k++)
{
for (int l = 0; l < 5; l++)
{
for (int m = 0; m < 6; m++)
{
for (int n = 0; n < 7; n++)
{
Console.WriteLine(myArray[i, j, k, l, m, n]);
}
}
}
}
}
}
```
这个代码中,我们首先定义了一个6维的字符串数组 `myArray`,并使用6个嵌套的for循环填充数组的每个元素。然后,我们再次使用6个嵌套的for循环遍历数组的每个元素,并使用 `Console.WriteLine` 方法将其输出到控制台窗口。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![cs](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)