LoginSignup
0
0

More than 5 years have passed since last update.

[C#] 配列に対するfor ,foreach

Posted at

配列でforeachで行うと、要素数全てに対して処理を行う。
https://docs.microsoft.com/ja-jp/dotnet/csharp/programming-guide/arrays/using-foreach-with-arrays

配列string[10,2]があった場合に、[i,0]に対して処理を行いたいなら

for (int i = 0; i < array.GetLength(0); i++)
{
array[i,0]の処理
}

配列string[10,2]があった場合に、[0,i]に対して処理を行いたいなら

for (int i = 0; i < array.GetLength(1); i++)
{
array[0,i]の処理
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0