2017-09-12 13 views
0

ループ内に2つの値を設定することはできますか?forループ?私は、最初の要素(i)は変数であり、第二(j)は、私が例えばi値を設定したい2つの値を1つの行列に設定する

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(); 
} 

そしてここ

一定である[、]文字列行列を作成したいと思います: 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

私はあなたが何をしたいのかよく分からないが、あなたは、このようなループのために複数の変数を宣言することができます。

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(); 
} 
関連する問題