C# 기초강의 4_ 배열

Park Yeeun·2023년 6월 29일
0

C# 기초공부

목록 보기
4/10

📌 1차원 배열

✔ 선언

int[] a = { 1, 2, 3, 4 };
string[] vars = {"aaa", "bbb", "ccc"};

✔ 출력

Console.WriteLine(a[0]);				// 1
Console.WriteLine(a[a.Length - 1]);		// 4

📌 2차원 배열

1차원 배열을 여러개 가질 수 있음

3차원배열은 2차원 배열을 여러개 가지는 것

✔ 선언

int[,] abc = { { 1, 2, 3 } , { 4, 5, 6 } };

✔ 출력

Console.WriteLine(abc[0, 2]);	//3

📌 가변 2차원배열

int[][] hello = new int[3][];
hello[0] = new int[4];
hello[1] = new int[3];
hello[2] = new int[2];

hello[2][1] = 4;

Console.WriteLine(hello[0][0]);		// 0
Console.WriteLine(hello[2][1]);		// 4
profile
새싹 개발자입니당 🌱

0개의 댓글