본문 바로가기
반응형

분류 전체보기500

백준 C# 10871 using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { string input_n = Console.ReadLine(); string[] token_n = input_n.Split(); int n = int.Parse(token_n[0]); int x = int.Parse(token_n[1]); string input_list = Console.ReadLine(); string[] token = input_list.Split(); int[] arr = new int[n]; for(int i=0; i 2023. 4. 11.
백준 C# 10807 using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { string input_n = Console.ReadLine(); int n = int.Parse(input_n); string input_list = Console.ReadLine(); string[] token = input_list.Split(); List list = new List(); string input_v = Console.ReadLine(); int v = int.Parse(input_v); int count = 0; for(int i=0; i 2023. 4. 11.
C# 문법 - 상속성 1. 상속성의 필요성 중복되는 데이터를 비효율적으로 사용하는 것을 막기 위해 사용한다. class Pig { public string name; } class Cat { public string name; } class Dog { public string name; } 2. 필드에서 상속성 사용법 01 부모 클래스 / 기반 클래스 class Animal { public string name; public Animal() { } } 02 자식 클래스 / 파생 클래스 class class Pig : Animal { public Pig() { } } 생성자를 호출하게되면 부모 클래스의 기본 생성자가 호출 되고 자식 클래스 생성자가 호출되는 것을 확인 할 수 있다. 03 부모 클래스 생성자 고르는 법 base(.. 2023. 4. 11.
C# 문법 - static class - 붕어빵 틀 field - 붕어빵에 대한 정보 붕어빵이 같은 틀에 나왔다고 해도 붕어빵 마다 맛과 비율이 다른 것 처럼 각 인스턴스마다 다르다. instance- 붕어빵 Pig pig = new Pig(); Pig pig2 = new Pig(); pig2.weight = 80; // 붕어빵에 대한 정보 Pig pig3 = new Pig(); pig3.weight = 110; // 붕어빵에 대한 정보 1. static 만약 static이라고 선언을 하면 age라는 필드는 인스턴스(붕어빵)에 종속되는 것이 아니라 class(붕어빵 틀)에 종속되는 것이다. 그러므로 age의 값은 인스턴스가 만들어질때 다 같은 값으로 만들어지게 된다. 즉, 오로지 1개만 존재한다. static public int .. 2023. 4. 11.
C# 문법 - this 키워드 1. this 키워드 weight는 생성자에서 받은 weight이 아니라 내 자신의 weight이므로 이를 명시하기 위해 this를 사용한다. static void Main(string[] args) { Pig pig = new Pig(50); } 2. this 키워드를 이용해서 생성자 호출 this()는 생성자를 특정해서 먼저 실행시켜준다. public Pig(int weight) : this() static void Main(string[] args) { Pig pig = new Pig(50); } public Pig(int weight, string name) : this(weight) static void Main(string[] args) { Pig pig = new Pig(50,"pig"); .. 2023. 4. 11.
C# 문법 - 생성자 1. 생성자 생성자 이름은 클래스 이름과 같아야 한다. 반환하는 타입을 아무것도 지정해주면 안된다. class Pig { public string name; public int weight; public Pig() { name = "piggy"; weight = 100; Console.WriteLine("생성자 호출!"); } } 2. 생성자 사용 클래스 또는 구조체가 인스턴스화되면 생성자가 호출된다. new연산자를 사용하면 클래스를 인스턴스화 한다. 새 개체에 메모리가 할당된 후 new 연산자가 생성자를 호출한다. static void Main(string[] args) { Pig pig = new Pig(); } 본 게시글은 MMORPG Part1을 수강하고 정리한 글입니다. https://www.i.. 2023. 4. 11.
반응형