본문 바로가기

언어 정리/C# 개념 및 lib13

구조체, 인터페이스, 열거형(enum), 튜플, 네임드튜플, 딕셔너리, Nullable 자료형 종류 및 예시 값 형식 (Value Types) 기본 자료형 (Primitive Types): int, float, double, bool, char 등 구조체 (Structs): DateTime, TimeSpan 등 열거형 (Enums): 사용자 정의 열거형 참조 형식 (Reference Types) 클래스 (Classes): object, string 등 인터페이스 (Interfaces) 배열 (Arrays) 대리자 (Delegates) 컬렉션 (Collections) List: 가변 크기의 순차적 목록 LinkedList: 양방향 연결 목록 Queue: FIFO (선입선출) 구조 Stack: LIFO (후입선출) 구조 HashSet: 유일한 요소를 저장하는 집합 Dictionary: 키-값 .. 2024. 1. 9.
상속과 다형성 상속은 클래스가 다른 클래스의 속성과 메소드를 그대로 받아오는 것이고, 다형성은 같은 이름의 메소드가 다른 행동을 할 수 있게 하는 것이다. 상속을 활용하면, 코드의 재사용성을 높이고, 중복을 줄이고 다형성을 활용하면, 동일한 인터페이스에 대해 다양한 구현을 제공할 수 있어 코드의 유연성이 증가한다. - 다형성은 주로 메소드 오버라이딩(overriding)이나 오버로딩(overloading)을 통해 구현되며, 각각 메소드 오버라이딩은 하위 클래스가 상위 클래스의 메소드를 재정의하고 오버로딩은 같은 이름의 메소드가 매개변수의 유형이나 개수에 따라 다른 동작을 하는 것을 의미한다. 상속 - 키워드 base, this base 는 상위 클래스 객체를 의미 this 는 해당 객체(하위클래스) 를 의미 ex) 생.. 2024. 1. 9.
생성자 인자의 갯수와 자료형에 따라 대응하는 생성자 템플릿 + 오버로딩 생성자(overloaded constructor) 사용 코드 using System; public class Test { public T_1 First { get; set; } public T_2 Second { get; set; } // 인자로 하나만 오는 경우 public Test(T_1 first) { this.First = first; this.Second = default(T_2); } // 인자로 두 개가 오는 경우 public Test(T_1 first, T_2 second) { this.First = first; this.Second = second; } } class Program { static void Main() { T.. 2024. 1. 9.
var, foreach, List 자료형 var 2024. 1. 8.
if 문 for 문 while 문 Console.WriteLine("-------------------------------------------------"); Console.WriteLine("if 문 for 문 while 문"); int a = 5; int b = 3; int c = 4; if (a + b > 10) { Console.WriteLine("The answer is greater than 10"); } else { Console.WriteLine("The answer is not greater than 10"); } if ((a + b + c > 10) && (a == b)) { Console.WriteLine("The answer is greater than 10"); Console.WriteLine("And the .. 2024. 1. 8.
정수 연산 Console.WriteLine("-------------------------------------------------"); Console.WriteLine("정수, 연산 ..."); int a = 18; int b = 6; int c = a + b; Console.WriteLine(c); c = a / b; Console.WriteLine(c); c = a % 10; Console.WriteLine(c); int max = int.MaxValue; int min = int.MinValue; Console.WriteLine($"The range of integers is {min} to {max}"); int what = max + 3; Console.WriteLine($"An example of o.. 2024. 1. 8.