C#
57. ์ผ๋ฐํ ํ๋ก๊ทธ๋๋ฐ ์์ ๋ชจ์
using System; using System.Collections; namespace CopyingArray { class MainApp { static void CopyArray(T[] source, T[] target) { for (int i = 0; i < source.Length; i++) target[i] = source[i]; } static void Main(string[] args) { int[] source = {1,2,3,4,5}; int[] target = new int[source.Length]; CopyArray(source, target); foreach (var element in target) Console.WriteLine(element); string[] source2..

56. ์ผ๋ฐํํ ๋, ํ์ ๋งค๊ฐ๋ณ์ ์ ์ฝ์ํค๊ธฐ
์ผ๋ฐํ ํ๋ก๊ทธ๋๋ฐ(์๋ ์์์ ์ฐธ๊ณ ํ์ฌ ํ์ตํ์์ต๋๋ค.) https://youtu.be/etvC-lj39ws ch11 ์ผ๋ฐํ ํ๋ก๊ทธ๋๋ฐ (tistory.com)
55. foreach๊ฐ ๊ฐ๋ฅํ ๊ฐ์ฒด ๋ง๋ค๊ธฐ
foreach ๋ฌธ์ for ๋ฌธ ์ฒ๋ผ ์์์ ์์น๋ฅผ ์ํ ์ธ๋ฑ์ค ๋ณ์๋ฅผ ์ ์ธํ ํ์ ์๋ค. foreach๋ฌธ์ ์๋ฌด ํ์์ ๊ฐ์ฒด์์๋ ์ฌ์ฉํ ์ ์๋ ๊ฒ์ด ์๋๋ค. ๋ฐฐ์ด์ด๋ ๋ฆฌ์คํธ ๊ฐ์ ์ปฌ๋ ์ ์์๋ง ์ฌ์ฉํ ์ ์๋ค. foreach๋ฌธ์ด ๊ฐ์ฒด ๋ด์ ์์๋ฅผ ์ํํ๊ธฐ ์ํด์๋ foreach๋ฌธ๊ณผ์ ์ฝ์์ ์ง์ผ์ผ ํ๋๋ฐ, ์ฝ์์ด ๋ญ๋ค? ์ธ.ํฐ.ํ.์ด.์ค foreach ๊ตฌ๋ฌธ์ IEnumerable์ ์์ํ๋ ํ์๋ง ์ง์ํ๋ค. ์ฆ, ํด๋์ค๋ IEnumerable์ ์์ํ๊ธฐ๋ง ํ๋ฉด foreach ๋ฌธ์ ์ด์ฉํด์ ์์๋ฅผ ์ํํ ์ ์๊ฒ ํ ์ ์๋ค๋ ์ด์ผ๊ธฐ์ด๋ค. IEnumerable ์ธํฐํ์ด์ค๊ฐ ๊ฐ๊ณ ์๋ ๋ฉ์๋๋ ๋ค์๊ณผ ๊ฐ์ด ๋จ ํ๋ ๋ฟ์ด๋ค. MyList๋ ์ด ๋ฉ์๋๋ฅผ ๊ตฌํํด์ผ ํ๋ค. ๋ฉ์๋ ์ค๋ช IEnumerator Get..
54. ์ธ๋ฑ์
์ธ๋ฑ์๋ ์ธ๋ฑ์ค๋ฅผ ์ด์ฉํด์ ๊ฐ์ฒด ๋ด์ ๋ฐ์ดํฐ์ ์ ๊ทผํ๊ฒ ํด์ฃผ๋ ํ๋กํผํฐ์ด๋ค. ๊ฐ์ฒด๋ฅผ ๋ง์น ๋ฐฐ์ด์ฒ๋ผ ์ฌ์ฉํ๊ฒ ํด์ค๋ค. class ํด๋์ค์ด๋ฆ { ํ์ ์ ์ธ๋ฑ์ํ์ this[ํ์ index] //์ธ๋ฑ์ค์ ์๋ณ์๊ฐ ๊ผญ index์ผ ํ์์๋ค. ์ทจํฅ๊ป ์กฐ์ ! { get{ //index๋ฅผ ์ด์ฉํ์ฌ ๋ด๋ถ ๋ฐ์ดํฐ ๋ฐํ} set{ //index๋ฅผ ์ด์ฉํ์ฌ ๋ด๋ถ ๋ฐ์ดํฐ ์ ์ฅ} } } ์ธ๋ฑ์๋ ํ๋กํผํฐ์ฒ๋ผ ์๋ณ์๋ฅผ ๋ฐ๋ก ๊ฐ์ง์ง ์๋๋ค! ํ๋กํผํฐ๋ ๊ฐ์ฒด ๋ด์ ๋ฐ์ดํฐ์ ์ ๊ทผํ๋ ํต๋ก์ธ๋ฐ, ํ๋กํผํฐ๊ฐ ์ด๋ฆ์ ํตํด ๊ฐ์ฒด ๋ด์ ๋ฐ์ดํฐ์ ์ ๊ทผํ๊ฒ ํด์ค๋ค๋ฉด, ์ธ๋ฑ์๋ ์ธ๋ฑ์ค๋ฅผ ํตํด ๊ฐ์ฒด ๋ด์ ๋ฐ์ดํฐ์ ์ ๊ทผํ๊ฒ ํด์ค๋ค. ์ธ๋ฑ์์ ์ ์ธ ์ MyList๋ ๋ด๋ถ์ ์ ์ ํ์ ๋ฐฐ์ด์ ๊ฐ์ง๊ณ ์๊ณ , ์ธ๋ฑ์๋ฅผ ํตํด ์ด ๋ฐฐ์ด์ ์ ๊ทผํ๋ค. ์ธ๋ฑ์๋ฅผ ํตํด..
53. ์ปฌ๋ ์ (ArrayList, Queue, Stack, Hashtable)
์ปฌ๋ ์ ์ด๋ ๊ฐ์ ์ฑ๊ฒฉ์ ๋ ๋ฐ์ดํฐ์ ๋ชจ์์ ๋ด๋ ์๋ฃ๊ตฌ์กฐ๋ฅผ ๋งํ๋ค. public abstrack class Array : ICloneable, IList, ICollection, IEnumerable - ArrayList ๊ฐ์ฅ ๋ฐฐ์ด๊ณผ ๋ฎ์ ์ปฌ๋ ์ ์ด๋ค. ์ปฌ๋ ์ ์ ์์์ ์ ๊ทผํ ๋๋ [ ] ์ฐ์ฐ์๋ฅผ ์ด์ฉํ๊ณ , ํน์ ์์น์ ์๋ ์์์ ๋ฐ์ดํฐ๋ฅผ ์์๋ก ํ ๋นํ ์ ์๋ค. ํํธ, ๋ฐฐ์ด๊ณผ๋ ๋ฌ๋ฆฌ ์ปฌ๋ ์ ์ ์์ฑํ ๋ ์ฉ๋์ ๋ฏธ๋ฆฌ ์ง์ ํ ํ์ ์์ด ํ์์ ๋ฐ๋ผ ์๋์ผ๋ก ๊ทธ ์ฉ๋์ด ๋์ด๋๊ฑฐ๋ ์ค์ด๋ ๋ค. ArrayList์์ ๊ฐ์ฅ ์ค์ํ ๋ฉ์๋๋ Add(), RemoveAt(), Insert() ์ด๋ ๊ฒ ์ธ ๊ฐ์ด๋ค. Add() : ์ปฌ๋ ์ ์ ๊ฐ์ฅ ๋ง์ง๋ง์ ์๋ ์์ ๋ค์ ์ ์์๋ฅผ ์ถ๊ฐ RemoveAt() : ํน์ ์ธ๋ฑ์ค์ ..
52. ๊ฐ๋ณ๋ฐฐ์ด
์ง์ ํ ์๋ฏธ์์ ๋ฐฐ์ด์ ์์๋ก ๊ฐ๋ ๋ฐฐ์ด์ ๊ฐ๋ณ ๋ฐฐ์ด์ด๋ค. ๊ฐ๋ณ ๋ฐฐ์ด์ ๋ค์ํ ๊ธธ์ด์ ๋ฐฐ์ด์ ์์๋ก ๊ฐ๋ ๋ค์ฐจ์ ๋ฐฐ์ด๋ก ์ด์ฉ๋ ์ ์๋ค. ๊ฐ๋ณ ๋ฐฐ์ด์ ๋ค์ฐจ์ ๋ฐฐ์ด๊ณผ ๋ฌ๋ฆฌ ๋ฐฐ์ด์ ์์๋ก ์ฌ์ฉํด ์ ๊ทผํ ์ ์๋ค. ๊ฐ๋ณ ๋ฐฐ์ด์ ๋ค์๊ณผ ๊ฐ์ด ์ ์ธํ๋ค. ๋ฐ์ดํฐํ์[ ][ ] ๋ฐฐ์ด์ด๋ฆ = new ๋ฐ์ดํฐํ์[๊ฐ๋ณ ๋ฐฐ์ด์ ์ฉ๋][ ]; 2์ฐจ์ ๋ฐฐ์ด์ [ ]๋ฅผ ํ๋๋ง ์ฐ๊ณ ๊ทธ ์์ ์ฒจ์๋ฅผ ๋ ๊ฐ ์ฌ์ฉํ ๋ฐ๋ฉด, ๊ฐ๋ณ ๋ฐฐ์ด์ [ ]์ด ๋ ๊ฐ ์ด๋ค. ๊ฐ๋ณ ๋ฐฐ์ด์ ์์๋ก ์ ๋ ฅ๋๋ ๋ฐฐ์ด์ ๊ทธ ๊ธธ์ด๊ฐ ๋ชจ๋ ๊ฐ์ ํ์๊ฐ ์๋ค. ๊ทธ๋์ Jagged ๋ฐฐ์ด์ด๋ผ๊ณ ํ๋ ๊ฒ์ด๋ค. ์ฉ๋์ด 3๊ฐ์ธ ๋ฐฐ์ด jagged๋ฅผ ์ ์ธํ ๋ค์, jagged์ ๊ฐ ์์์ ํฌ๊ธฐ๊ฐ ๊ฐ๊ฐ ๋ค๋ฅธ ๋ฐฐ์ด๋ค์ ํ ๋นํ๋ค. 0๋ฒ ์์์๋ ๊ธธ์ด๊ฐ 5์ธ ๋ฐฐ์ด, 1๋ฒ ์์์๋ ๊ธธ์ด..
51. ๋ค์ฐจ์๋ฐฐ์ด
int[,,] array = new int[4, 3, 2] { { {0,1}, {2,3 }, {4,5 } }, { {6,7 }, {8,9 }, {10,11 } }, { {12,13 }, {14,15 }, {16,17 } }, { {18,19 }, {20,21 }, {22,23 } }, }; using System; namespace MoreOnArray { class MainApp { static void Main(string[] args) { int[,,] array = new int[4, 3, 2] { { {0,1}, {2,3 }, {4,5 } }, { {6,7 }, {8,9 }, {10,11 } }, { {12,13 }, {14,15 }, {16,17 } }, { {18,19 }, {20,21 },..
50. 2์ฐจ์ ๋ฐฐ์ด
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์ฐจ์ ๋ฐฐ์ด์ ์ฝ๋์์ ์ฝ์ ๋๋ [] ์์ ์๋ ์ฐจ์์ ๊ธธ์ด๋ฅผ ๋ค์์๋ถํฐ ์ฝ์ผ๋ฉด ์ดํดํ๊ธฐ ์ฝ๋ค.) int[,] ..
49. Array๋ก ์ํ๋ฒณ ์ถ๋ ฅํ๋ ์์
using System; namespace MoreOnArray { class MainApp { static void PrintArray(System.Array array) { foreach (var e in array) Console.WriteLine(e); Console.WriteLine(); } static void Main(string[] args) { //'Z'๋ ์์คํค์ฝ๋๋ก 90, 'A'๋ 65์ด๋ค. ๋๋ฌธ์ ์ํ๋ฒณ ๊ฐ์๋ ๋ชจ๋ 90-65+1('Z'-'A'+1), ์ฆ 26์ด๋ค. char[] array = new char['Z'-'A'+1]; for (int i = 0; i < array.Length; i++) array[i] = (char)('A' + i); PrintArray(array); }..
ํด๋์ค๋ฅผ ๋ฐฐ์ด๋ก ์ ์ธํ๊ธฐ
C#์์ class๋ฅผ ๋ฐฐ์ด๋ก ์ ์ธํ์ฌ ์ฌ์ฉํ ๊ฒฝ์ฐ์๋, ์๋ ์์ ์ ๊ฐ์ด ๋ฐฐ์ด ์ ์ธ์์ new ํค์๋๋ฅผ ์ ์ธํ๊ณ , ๋ค์ ํ๋ฒ ๊ฐ๋ณ ์์๋ง๋ค new ์ ์ธ์ ํด ์ฃผ์ด์ผ ํ๋ค. ์คํ์ดํ๋์ฉ๋ท - ๋ฐ๋ปํ๊ฒ ์ฆ๊ธฐ๋ ์ฝ๋ฉ ํ ์~โช :: [C#] ํด๋์ค๋ฅผ ๋ฐฐ์ด๋ก ์ ์ธํ๊ธฐ (tistory.com) [C#] ํด๋์ค๋ฅผ ๋ฐฐ์ด๋ก ์ ์ธํ๊ธฐ ์.. ์ด๊ฑฐ ์ ๋ง ๋ชฐ๋๋์? C# ํด๋์ค์ ์ธ์คํด์ค๋ฅผ ๋ฐฐ์ด๋ก ์ ์ธํ ๋ ๋์ ์ผ๋ก ์ ์ฒด ํ ๋นํ ๋ค, ๋ค์ ํ๋ํ๋ ๋ค ํ ๋นํด์ค์ผ ํ๋ค๋. ์ด๊ฑฐ ๋๋ฌธ์ ์ด์ ์ค๋ ํค๋ฉ๊ฑฐ ์๊ฐํ๋ฉด..@#$%& ์ถ์ฒ:hazelstyle.e topnanis.tistory.com ์ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํด์ ์์ ๋ฅผ ์์ฑํ์๋ค. using System; namespace MoreOnArray { class Test { int nu..