(C#) 27. 다차원 배열 (multi-array)
Data Structure
(C#) 27. 다차원 배열 (multi-array)
(Multi-array) : Data Structure
- 최초 작성일: 2021년 3월 21일(월)
##
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
namespace multiArray
{
class Program
{
class Map
{
int[,] tiles =
{
{ 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1 }
};
public void Render()
{
for (int y = 0; y < tiles.GetLength(1); y++)
{
for (int x = 0; x < tiles.GetLength(0); x++)
{
if (tiles[y, x] == 1)
Console.ForegroundColor = ConsoleColor.Red;
else
Console.ForegroundColor = ConsoleColor.Green;
Console.Write('\u25cf');
}
Console.WriteLine();
}
}
}
static void Main(string[] args)
{
Map map = new Map();
map.Render();
// int[,] map = new int[2, 3];
//[ . . ]
//[ . . . . . . ]
//[ . . . ]
//int[][] a = new int[3][];
//a[0] = new int[3];
//a[1] = new int[6];
//a[2] = new int[2];
//a[0][0] = 1;
/*
// 다차원 배열
int[] scores = new int[5] { 10, 30, 40, 20, 50 };
//int[,] arr = new int[2, 3] { { 1, 2, 3 }, { 1, 2, 3 } };
int[,] arr = new int[,] { { 1, 2, 3 }, { 1, 2, 3 } };
arr[0, 0] = 1;
arr[1, 0] = 1;
// 2층 [ . . . ]
// 1층 [ . . . ]
*/
}
}
}
Result
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
