是否可以在一个for
循环中设置两个值?我想创建一个字符串矩阵[,],第一个元素(i)是变量,第二个(j)是常量
int rowRun = 1;
string[,] costume = new string [elementsOfRunning, rowRun];
int columnRun = costume.GetLength(0);
for (int i = 0; i < columnRun; i++)
{
int rowOfRunning;
do
{
Console.WriteLine("Row of running (0-42)");
rowOfRunning = int.Parse(Console.ReadLine());
}
while (!(0 <= rowOfRunning && rowOfRunning <= 42));
string rowOfRunning2 = rowOfRunning.ToString();
}
在这里,我想设置i
值,例如:costume[i,j] = rowOfRunning;
但我不能这样做。
for (int j = 0; j < rowRun; j++)
{
string comment = "";
do
{
Console.WriteLine("Write a comment: („verseny”, „terep”, „laza”, „fartlek”, „résztáv”");
comment = Console.ReadLine();
}
while (!comment.Contains(",") && comment != "verseny" && comment != "terep" && comment != "laza" && comment != "fartlek" && comment != "résztáv");
costume[i, j] = comment;
Console.WriteLine(costume[i,j]);
}
答案 0 :(得分:0)
我不确定你想做什么,但是你可以像这样在for循环中声明多个变量:
var array = new Array[10, 10];
for (int i = 0, j = 1; i < 3; j++, i++)
{
Console.WriteLine("i:" + i + " j:" + j);
array[i,j] = Console.ReadLine();
}