728x90 ๋ฐ์ํ C#3 [C# ๊ธฐ์ด] ๋คํ์ฑ/์์ ๋คํ์ฑ ๋งค๊ฐ๋ณ์๋ก ๋ฐ์ ์ซ์ 2๊ฐ๋ฅผ ๋ํด์ฃผ๋ ๋ฉ์๋๋ฅผ ๋ง๋ค๊ณ , ์ค๋ฒ๋ก๋ฉ์ ์์ผ๋ณด๊ฒ ๋ค. ์ค๋ฒ๋ก๋ฉ์ ์กฐ๊ฑด 1. ๋ ๋ฉ์๋์ ์ด๋ฆ์ด ๊ฐ๋ค. 2. ๋งค๊ฐ๋ณ์์ ๊ฐ์ ๋๋ ํ์ ์ด ๋ฌ๋ผ์ผํ๋ค. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 class Calculate { public static int add(int a, int b) //์ ์ ๋ฉ์๋ (ํด๋์ค๋ฅผ ํตํ ํธ์ถ) { ; Console.WriteLine("int add"); int ret = a + b; return ret; } public float add(float a, float b)//๊ฐ์ฒด๋ฅผ ํตํด์ ํธ์ถ {.. 2021. 7. 27. [C#๊ธฐ์ด] ๋ณต์ฌ ์์ฑ์/ static ๋ณต์ฌ ์์ฑ์ ์๊ธฐ ์์ ๊ณผ ๊ฐ์ ํํ์ ๊ฐ์ฒด๋ฅผ ์ธ์๋ก ๋ฐ๋ ์์ฑ์๋ฅผ ์๋ฏธํ๋ค. ํ์๋ค์ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ Student ํด๋์ค๋ฅผ ๋ง๋ค์ด๋ณด๊ฒ ๋ค. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 class Student { public int studentID; public int age; public String name; public Student(int studentID,int age,String name) { Console.WriteLine("์ธ์๋ฅผ ๋ฐ๋ ์์ฑ์"); this.studentID = studentID; this.age = a.. 2021. 7. 27. [C#๊ธฐ์ด] ์ฐธ์กฐ ์ฐธ์กฐ ref/out ํค์๋๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ์ธ๋ถ๋ก๋ถํฐ ๋ณ์๋ก๋ง ์ ๋ ฅ๋ฐ๊ฒ ๋ค๋ ์๋ฏธ๋ฅผ ๊ฐ์ง๋ค. --> ref a ์ด๋ฐ๊ฑด ๊ฐ๋ฅํ์ง๋ง ref 10 ๊ฐ์๊ฑด ๋ถ๊ฐ๋ฅ! ์ธ๋ถ๋ก๋ถํฐ ์ ์ฅ์๋ฅผ ๋ฐ์์ค๊ฒ ๋ค๋ ์๋ฏธ๋ฅผ ๊ฐ์ง. ref ํค์๋๋ ํจ์ ๋ด๋ถ๋ก๋ถํฐ ๋ฐ์์ฌ ๊ฐ์ด ์์ ๋ ์ฌ์ฉ ref ํค์๋๋ ๋ณ์๋ฅผ ์ด๊ธฐํํ ํ ์ ๋ฌํด์ผํ๋ค. out=์ด๊ธฐํ ์ํ๊ณ ์ ๋ฌํด๋ ๋จ,๊ฒฐ๊ณผ๊ฐ์ ๋ฐ์ผ๋ ค๊ณ ๋ง๋ ๊ฑฐ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 class Program { static void Test1(ref int r) { r = 30; } static void Test2(int r) { r = 20; } static void Main(string[] args.. 2021. 7. 19. ์ด์ 1 ๋ค์ 728x90 ๋ฐ์ํ