프로그래밍/C#
![[C#] 인자 전달 방식 (1)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FloZVN%2FbtqBZfPaOMX%2FksLRmE8pFDU9xr2NOSIwz0%2Fimg.png)
[C#] 인자 전달 방식 (1)
1. ref local variable using System; class Program { public static void Main() { int n1 = 10; int n2 = n1; n2 = 20; Console.WriteLine($"{n1}, {n2}"); int n3 = 10; ref int n4 = ref n3; n4 = 20; Console.WriteLine($"{n3}, {n4}"); } } C# 문법 중 ref int n4 = ref n3; 값 타입 앞에 ref 라고 붙이는 문법이 있다. 이렇게 만들면 정수형 변수를 만들지만 일반 변수가 아닌, 참조 변수로 만들겠다. 라는 뜻이다. 따라서 값을 직접 들지 않고 주소를 가지고 있다. 나중에 덩치가 큰 구조체를 만들었는데 코딩하며 복사본이 ..
![[C#] 다차원 배열, 가변 배열](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FS1DJP%2FbtqBXWhN0XX%2FuysGFnSKMx7xtOd5mIgho1%2Fimg.png)
[C#] 다차원 배열, 가변 배열
1. 다차원 배열 using System; clss Program { static void Main() { int[] arr = new int[3]; int[,] arr1 = new int[3, 2]; int[,] arr2 = new int[3, 2] {{1, 1}, {2, 2}, {3, 3}}; int[,] arr3 = new int[,] {{1, 1}, {2, 2}, {3, 3}}; int[,] arr4 = {{1, 1}, {2,2}, {3,3}}; arr1[0, 0] = 10; arr1[0, 1] = 20; foreach(int n in arr2) Console.WriteLine(n); int[,,] arr5 = new int[2, 2, 2]; int[,,,] arr6 = new int[2, 2, ..
![[C#] 배열 기본](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fcr29R0%2FbtqBXVJVw3y%2FZcXmoQBvmG9NJzAV29pzNk%2Fimg.png)
[C#] 배열 기본
1. 핵심 정리 using System; class Program { int[] arr1; int[] arr2 = new int[5]; int[] arr3 = new int[5] {1, 2, 3, 4, 5}; int[] arr4 = new int[] {1, 2, 3, 4, 5}; int[] arr5 = {1, 2, 3, 4, 5}; Type t = arr5.GetType(); Console.WriteLine(t.FullName); Console.WriteLine(arr5.Length); // 5 Console.WriteLine(arr5.GetLength(0)); // 5 Console.WriteLine(arr5.GetValue(3)); // 4 Console.WriteLine(arr5.GetLowerBo..
![[C#] Boxing / Unboxing (3)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Flpbcm%2FbtqBVMdPGSy%2FVMb5fKKv5fecbJW0Q3HEg0%2Fimg.png)
[C#] Boxing / Unboxing (3)
1. 핵심 정리 using System; class Point { private int x; private int y; public Point(int xPos, int yPos) { x = xPos; y = yPos; } } class Program { static void Main() { Point p1 = new Point(1, 1); Point p2 = new Point(1, 1); Console.WriteLine(p1.Equals(p2)); } } 이전과 비슷한 코드에 CompareTo가 아닌 Equals를 사용하고 있다. Equals는 object로부터 파생되어 언제나 사용할 수 있다. ① Equals vs CompareTo 메소드 Equals는 object로 부터 나왔으니 레퍼런스를 조사하고,..
![[C#] Boxing / Unboxing (2)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fba5OUE%2FbtqBSOxcsrS%2FIKWwoPjNrCcjjnfVhQKrEK%2Fimg.png)
[C#] Boxing / Unboxing (2)
1. 핵심 정리 using System; class Program { static void Main() { Console.WriteLine(10 < 20); // true Console.WriteLine(10.CompareTo(20)); // -1 Console.WriteLine(10.CompareTo(10)); // 0 Console.WriteLine(10.CompareTo(5)); // 1 string s1 = "AAA"; string s2 = "BBB"; Console.WriteLine(s1 < s2); Console.WriteLine(s1.CompareTo(s2)); // -1 } } ① 객체의 크기를 비교하는 방법 C#에서 객체의 크기를 비교하는 방법은 관계연산자와 CompareTo메소드가 있다..
![[C#] Boxing / Unboxing (1)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2F157LQ%2FbtqBQnsW22G%2FR5CiVPdJmmWGNE7a2dkJRk%2Fimg.png)
[C#] Boxing / Unboxing (1)
1. 핵심 정리 using System; class Program { static void Main() { int[] a1 = {1, 2, 3}; object o1 = a1; int[] a2 = (int[])o1; Console.WriteLine(a2[0]); } } 먼저 5~9번 라인을 보자. 먼저 int형의 배열을 만들었다. 배열은 C#에서 참조타입이므로 Heap에 생성되었을 것이다. 다음 object는 모든 타입의 기반 타입이므로 o1도 a1과 같은 Heap을 바라볼 것이다. 마지막으로 위의 obejct타입을 다시 배열로 캐스팅하여 담을 수도 있다. 그림으로 나타내면 아래와 같다. 모두 같은 메모리를 바라보기에 만약 중간에서 a1이나 o1의 값을 바꿔도 a2를 출력해보면 바뀐 값으로 출력되는 것을 ..