๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

๐Ÿ–ฅ๏ธ135

[C#] ๊นŠ์€๋ณต์‚ฌ ์–•์€๋ณต์‚ฌ, readonly, ๊ตฌ์กฐ์ฒด, ํŠœํ”Œ ๊นŠ์€ ๋ณต์‚ฌ/์–•์€ ๋ณต์‚ฌ ์–•์€ ๋ณต์‚ฌ(Shallow Copy): ๋™์ผํ•œ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋ฅผ ๊ณ ์œ ํ•จ -> ๊ฐ™์ด ๋ณ€ํ•จ using System; class Program { static void Main() { int[] originalArray = { 1, 2, 3 }; int[] shallowCopyArray = (int[])originalArray.Clone(); shallowCopyArray[0] = 99; Console.WriteLine("Original Array: " + string.Join(", ", originalArray)); // ์ถœ๋ ฅ: Original Array: 1, 2, 3 Console.WriteLine("Shallow Copy Array: " + string.Join(", ", shallow.. 2023. 8. 17.
[C#] ๋ถ„ํ•  ํด๋ž˜์Šค, ํ™•์žฅ ๋ฉ”์„œ๋“œ ๋ถ„ํ•  ํด๋ž˜์Šค (partial) ํ•˜๋‚˜์˜ ํด๋ž˜์Šค๋ฅผ ์•ž์— partial ํ‚ค์›Œ๋“œ๋ฅผ ๋ถ™์—ฌ์„œ ๋‚˜๋ˆ ์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค. partial class MyClass { public void MethodPart1() { Console.WriteLine("Method from Part 1"); } } partial class MyClass { public void MethodPart2() { Console.WriteLine("Method from Part 2"); } } class Program { static void Main() { MyClass myClass = new MyClass(); myClass.MethodPart1(); // ์ถœ๋ ฅ: "Method from Part 1" myClass.MethodPart2(); .. 2023. 8. 17.
[C#] ์ƒ์†, ๋‹คํ˜•์„ฑ, ์˜ค๋ฒ„๋ผ์ด๋”ฉ ์ƒ์†: base ํ‚ค์›Œ๋“œ ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋‚˜ ๋ฉค๋ฒ„์— ์ ‘๊ทผํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. class Parent { public void SomeMethod() { Console.WriteLine("Parent's method"); } } class Child : Parent { public void CallParentMethod() { base.SomeMethod(); // ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ } } ์œ„ ์˜ˆ์‹œ๋Š” base๊ฐ€ ์—†์–ด๋„ ์ž˜ ์ž‘๋™ํ•œ๋‹ค. (๋ถ€๋ชจ ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์†๋ฐ›์•˜๊ธฐ ๋•Œ๋ฌธ์—) ํ•˜์ง€๋งŒ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด base๋ฅผ ๋ถ™์—ฌ์ฃผ๊ธฐ๋„ ํ•œ๋‹ค. ๋งŒ์•ฝ ์˜ค๋ฒ„๋ผ์ด๋”ฉ์„ ํ•œ๋‹ค๋ฉด ๊ผญ base ํ‚ค์›Œ๋“œ๋กœ ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ์™€ ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌ๋ถ„ํ•ด์ค˜์•ผ ํ•œ๋‹ค. class Parent { public virtual void .. 2023. 8. 17.
[์ด๊ฒƒ์ด C#์ด๋‹ค] Chapter06: ์—ฐ์Šต๋ฌธ์ œ 1. Square() ๋ฉ”์†Œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ด ํ”„๋กœ๊ทธ๋žจ์„ ์™„์„ฑํ•˜์„ธ์š”. Square() ํ•จ์ˆ˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ œ๊ณฑํ•˜์—ฌ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. using System; namespace Chapter06Practice class MainApp { static double Square(double x) { return x * x; } static void Main(string[] args) { Console.Write("์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”: "); string str = Console.ReadLine(); if (!double.TryParse(str, out double d) && !int.TryParse(str, out int i)) { Console.WriteLine("์ •์ˆ˜ ํ˜น์€ ์‹ค์ˆ˜๋งŒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"); } else { double.. 2023. 8. 16.
[C#] ์ฐธ์กฐ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ „๋‹ฌ, ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ’return, ๊ฐ€๋ณ€ ๊ฐœ์ˆ˜์˜ ์ธ์ˆ˜, ์„ ํƒ์  ์ธ์ˆ˜ ์ฐธ์กฐ์— ์˜ํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜ ์ „๋‹ฌ ๋ณดํ†ต ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ์— ์ธ์ˆ˜๋ฅผ ์ „๋‹ฌํ•  ๋•Œ, ๋ฐ์ดํ„ฐ๊ฐ€ ๋ณต์‚ฌ๋˜์–ด์„œ ์ „๋‹ฌ๋œ๋‹ค. ๋งŒ์•ฝ ์ฃผ์†Œ๊ฐ’์„ ๋ณด๋‚ด๊ณ  ์‹ถ๋‹ค๋ฉด ์•ž์— ref๋ฅผ ๋ถ™์—ฌ์ฃผ๋ฉด ๋œ๋‹ค. class Program { public static void Main(string[] args) { int x = 3; int y = 4; Console.WriteLine($"x = {x}, y = {y}"); Swap(x, y); Console.WriteLine($"x = {x}, y = {y}"); SwapRef(ref x, ref y); Console.WriteLine($"x = {x}, y = {y}"); } static void Swap(int a, int b) { int temp = b; b = a; a = temp; } static vo.. 2023. 8. 16.
[์ด๊ฒƒ์ด C#์ด๋‹ค] Chapter05: ์—ฐ์Šต๋ฌธ์ œ 1. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ for๋ฌธ์„ ์ด์šฉํ•˜์—ฌ ์ž‘์„ฑํ•˜์„ธ์š”. * ** *** **** ***** for (int i=1; i 2023. 8. 16.
[C#] switch๋ฌธ๊ณผ switch์‹ switch๋ฌธ switch๋ฌธ์€ ์•„๋ž˜์™€ ๊ฐ™์ด case์— ๋งž๋Š” ๊ฐ’์„ ์ง€์ •ํ•ด ์ค„ ์ˆ˜ ์žˆ๋‹ค. int score = 95; string grade = ""; int score = (int)(Math.Truncate(input/10.0) * 10; //1์˜ ์ž๋ฆฌ๋ฅผ ๋ฒ„๋ฆผ switch (score) { case 90: grade = "A"; break; case 80: grade = "B"; break; case 70: grade = "C"; break; case 60: grade = "D"; break; default: grade = "F"; } switch ์‹ switch๋ฌธ์€ break;๋‚˜ case: ๋“ฑ ๋ฐ˜๋ณต๋˜๋Š” ์ฝ”๋“œ๊ฐ€ ๋งŽ์€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์ด๋•Œ, switch ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด ์ฝ”๋“œ์˜ ๊ธธ์ด๋ฅผ ์ค„์ด๊ณ  ๊ฐ€๋…์„ฑ์„ ๋†’์ผ .. 2023. 8. 16.
[์ด๊ฒƒ์ด C#์ด๋‹ค] Chapter4 ์—ฐ์Šต๋ฌธ์ œ 1. i++์™€ ++i์˜ ์ฐจ์ด์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”? i++๋Š” i๋ฅผ ๋จผ์ € ์‚ฌ์šฉํ•˜๊ณ  ์ดํ›„์— +1์„ ํ•œ๋‹ค๋Š” ๋œป์ด๊ณ , ++i๋Š” i์— ๋จผ์ € +1์„ ํ•˜๊ณ  i๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๋œป์ด๋‹ค. int a = 10; Console.WriteLine(a++); //10์„ ์ถœ๋ ฅํ•˜๊ณ  a๋Š” 11์ด ๋จ Console.WriteLine(++a); //11์— 1์„ ๋”ํ•ด์„œ 12๋ฅผ ์ถœ๋ ฅํ•จ 2. ๋‹ค์Œ ๋ณด๊ธฐ ์ค‘์—์„œ ๊ทธ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ์„ ์ฐพ์œผ์„ธ์š”. i = i+1; i++; ++i; i += 1; int i= 0; i = i + 1; Console.WriteLine(i); //1 i = 0; //i++; Console.WriteLine(i++); //0 i = 0; //++i; Console.WriteLine(++i); //1 i = 0; i += 1; Con.. 2023. 8. 16.
728x90

"); wcs_do();