c# 박싱 언박싱
[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)
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메소드가 있다..