728x90
2์ฐจ์ ๋ฐฐ์ด์ ๊ฐ๋ ์ ์ผ๋ก 2๊ฐ์ ์ฐจ์(์ธ๋ก+๊ฐ๋ก)์ผ๋ก ์์๋ฅผ ๋ฐฐ์นํ๋ค๊ณ ๋ ๋งํ๊ณ ,
1์ฐจ์ ๋ฐฐ์ด์ ์์๋ก ๊ฐ๋ ๋ฐฐ์ด์ด๋ผ๊ณ ๋ ํ๋ค.
2์ฐจ์ ๋ฐฐ์ด์ ์ ์ธ
๋ฐ์ดํฐํ์[,] ๋ฐฐ์ด์ด๋ฆ = new ๋ฐ์ดํฐํ์[2์ฐจ์๊ธธ์ด, 1์ฐจ์๊ธธ์ด];
1์ฐจ์์ ๊ธธ์ด๋ ๊ฐ๋ก ๋ฐฉํฅ,
2์ฐจ์์ ๊ธธ์ด๋ ์ธ๋ก ๋ฐฉํฅ.
int[,] test = new int[2, 3];
test[0, 0] = 1;
test[0, 1] = 2;
test[0, 2] = 3;
test[1, 0] = 4;
test[1, 1] = 5;
test[1, 2] = 6;
int[2,3]์ ๊ธธ์ด๊ฐ 3์ธ 1์ฐจ์ ๋ฐฐ์ด์ ์์๋ก 2๊ฐ ๊ฐ๊ณ ์๋ 2์ฐจ์ ๋ฐฐ์ด์ด๋ผ๊ณ ์ฝ๋๋ค.
(2์ฐจ์ ๋ฐฐ์ด์ ์ฝ๋์์ ์ฝ์ ๋๋ [] ์์ ์๋ ์ฐจ์์ ๊ธธ์ด๋ฅผ ๋ค์์๋ถํฐ ์ฝ์ผ๋ฉด ์ดํดํ๊ธฐ ์ฝ๋ค.)
<2์ฐจ์ ๋ฐฐ์ด์ ์ ์ธ>
int[,] test1 = new int[2, 3] { { 1,2,3},{4,5,6 } }; //๋ฐฐ์ด์ ํ์๊ณผ ๊ธธ์ด ๋ช
์
int[,] test2 = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };//๋ฐฐ์ด์ ๊ธธ์ด ์๋ต
int[,] test3 = { { 1, 2, 3 }, { 4, 5, 6 } };//ํ์๊ณผ ๊ธธ์ด ๋ชจ๋ ์๋ต
<์์ >
using System;
namespace MoreOnArray
{
class MainApp
{
static void Main(string[] args)
{
int[,] test1 = new int[2, 3] { { 1,2,3},{4,5,6 } };
for(int i=0; i<test1.GetLength(0); i++)
{
for(int j=0; j<test1.GetLength(1); j++)
{
Console.Write($"[{i},{j}]:[{test1[i,j]}]");
}
Console.WriteLine();
}
Console.WriteLine();
int[,] test2 = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };
for (int i = 0; i < test2.GetLength(0); i++)
{
for (int j = 0; j < test2.GetLength(1); j++)
{
Console.Write($"[{i},{j}]:[{test2[i, j]}]");
}
Console.WriteLine();
}
Console.WriteLine();
int[,] test3 = { { 1, 2, 3 }, { 4, 5, 6 } };
for (int i = 0; i < test3.GetLength(0); i++)
{
for (int j = 0; j < test3.GetLength(1); j++)
{
Console.Write($"[{i},{j}]:[{test3[i, j]}]");
}
Console.WriteLine();
}
}
}
}
์ถ๋ ฅ๊ฒฐ๊ณผ
[0,0]:[1][0,1]:[2][0,2]:[3]
[1,0]:[4][1,1]:[5][1,2]:[6]
[0,0]:[1][0,1]:[2][0,2]:[3]
[1,0]:[4][1,1]:[5][1,2]:[6]
[0,0]:[1][0,1]:[2][0,2]:[3]
[1,0]:[4][1,1]:[5][1,2]:[6]
728x90
'C# > ์ด๊ฒ์ด C#์ด๋ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
52. ๊ฐ๋ณ๋ฐฐ์ด (0) | 2022.02.25 |
---|---|
51. ๋ค์ฐจ์๋ฐฐ์ด (0) | 2022.02.25 |
49. Array๋ก ์ํ๋ฒณ ์ถ๋ ฅํ๋ ์์ (0) | 2022.02.24 |
48. System.Array (0) | 2022.02.24 |
47. ๋ฐฐ์ด์ฐ๋ ์ด์ , ๋ฐฐ์ด ์ด๊ธฐํ ๋ฐฉ๋ฒ 3๊ฐ์ง (0) | 2022.02.24 |