데이터형식[,] 배열이름 = new 데이터형식[2차원길이, 1차원길이];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
using System;
namespace ee
{
class MainApp
{
static void Main(string[] args)
{
int[,] arr = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.WriteLine("[{0}, {1}] : {2} ", i, j, arr[i, j]);
}
Console.WriteLine();
}
Console.WriteLine();
int[,] arr2 = new int[,] { { 1, 2, 3}, { 4, 5, 6 } };
for(int i = 0; i < arr2.GetLength(0); i++)
{
for (int j = 0; j < arr2.GetLength(1); j++)
{
Console.Write("[{0}, {1}] : {2}", i, j, arr2[i, j]);
}
Console.WriteLine();
}
Console.WriteLine();
int[,] arr3 = { { 1, 2, 3 }, { 4, 5, 6 } };
for(int i = 0; i < arr2.GetLength(0); i++)
{
for(int j = 0; j<arr2.GetLength(1); j++)
{
Console.Write("[{0]}, {1}] : {2}", i, j, arr3[i, j]);
}
Console.WriteLine();
}
Console.WriteLine();
}
}
}
|
cs |

'C#' 카테고리의 다른 글
임의의 두 자리 숫자 5개를 갖는 배열 생성 코드 (0) | 2022.07.25 |
---|---|
List<T> 356 (0) | 2022.07.22 |
배열을 초기화하는 세 가지 방법 (0) | 2022.07.22 |
foreach 문을 이용하여 점수를 출력하고 평균을 계산해서 출력하는 프로그램 (0) | 2022.07.22 |
1부터 100까지의 짝수, 홀수의 합을 구하시오. (0) | 2022.07.22 |