-
C# 배열 [array] (Let's study programming together)애드센스 승인 자료모음 2019. 4. 17. 11:04반응형
C# 변수와 상수 [Variables and constants] (Let's study programming together)
이전 포스팅에서 데이터 타입(https://lee-master.tistory.com/32)에 대해서 알아보았다. C# 데이터 타입[byte, short, int, float] (Let's study programming together) C# 데이터 타입 정의 주방엔 밥을 담는..
lee-master.tistory.com
앞 전 포스팅에선 변수와 상수에 대해 알아보았다.
선언해야 될 변수의 양이 4개일 땐
int a = 0, int b = 0, int c = 0, int d = 0;
만약 변수가 100개 이상 일 때도 위와 같이 선언해야 한다면 상당한 시간을 소요해야 될 것이다.
그러한 번거로움을 줄 일 수 있는 것이 바로 배열(array)이다.
단, 데이터 타입이 같은 그룹에 한해서 선언할 수 있다.
정수는 정수끼리, 문자열은 문자열끼리 선언한다.
배열에는 1차원 배열, 2차원 배열, 다차원 배열 등이 존재한다.
1) Source Code
1234567891011int
[] temp1 = { 1, 2, 3 };
// 1차원 배열
int
[,] temp2 = { { 1, 2 }, { 3, 4} };
// 2차원 배열
int
[,,] temp3 = { { { 1, 2, 3 },
// 3차원 배열
{ 4, 5, 6 },
{ 7, 8, 9 } },
{ { 10, 11, 12},
{ 13, 14, 15},
{ 16, 17, 18} }};
2) 구조
<그림1> 3) Index의 값
12345int
[] temp1 = { 1, 2, 3 };
// 1차원 배열
temp1[0]
// 값 : 1
temp2[1]
// 값 : 2
temp3[2]
// 값 : 3
123456int
[,] temp2 = { { 1, 2 }, { 3, 4} };
// 2차원 배열
temp2[0,0]
// 값 : 1
temp2[0,1]
// 값 : 2
temp2[1,0]
// 값 : 3
temp2[1,1]
// 값 : 4
12345678910111213141516171819202122232425262728293031int
[,,] temp3 = { { { 1, 2, 3 },
// 3차원 배열
{ 4, 5, 6 },
{ 7, 8, 9 } },
{ { 10, 11, 12},
{ 13, 14, 15},
{ 16, 17, 18} }};
temp3[0, 0, 0]
// 값 : 1
temp3[0, 0, 1]
// 값 : 2
temp3[0, 0, 2]
// 값 : 3
temp3[0, 1, 0]
// 값 : 4
temp3[0, 1, 1]
// 값 : 5
temp3[0, 1, 2]
// 값 : 6
temp3[0, 2, 0]
// 값 : 7
temp3[0, 2, 1]
// 값 : 8
temp3[0, 2, 2]
// 값 : 9
temp3[1, 0, 0]
// 값 : 10
temp3[1, 0, 1]
// 값 : 11
temp3[1, 0, 2]
// 값 : 12
temp3[1, 1, 0]
// 값 : 13
temp3[1, 1, 1]
// 값 : 14
temp3[1, 1, 2]
// 값 : 15
temp3[1, 2, 0]
// 값 : 16
temp3[1, 2, 1]
// 값 : 17
temp3[1, 2, 2]
// 값 : 18
다음 포스팅은 배열을 이용한 반복문(for)을 알아보겠다.
반응형'애드센스 승인 자료모음' 카테고리의 다른 글
누수! 말로만 듣던 나 홀로 소송, 그리고 전자 소송 [내용 증명] (0) 2022.12.20 배민커넥트 추천인코드 입력하고 만원 받으세요. (배달의 민족) (0) 2020.11.06 C# 변수와 상수 [Variables and constants] (Let's study programming together) (0) 2019.04.10 C# 데이터 타입[byte, short, int, float] (Let's study programming together) (1) 2019.04.09 C# 기초 (Let's study programming together) (0) 2019.04.09