C#/과제(9)
-
0329 스레드 복습
public class App { public App() { Thread t; ThreadStart ts = new ThreadStart(() => { for (int i = 0; i < 10; i++) { Console.WriteLine("Hello"); Thread.Sleep(500); } }); //스레드 인스턴스화 t = new Thread(ts); t.Start(); Thread t2 = new Thread(new ThreadStart(this.Hi)); t2.Start(); } private void Hi() { for (int i = 0; i < 10; i++) { Console.WriteLine("Hi"); Thread.Sleep(500); } } } Try/Catch/Finally 예외 ..
2021.03.29 -
0322 delegate 연습
delegate int Delelegate(int a, int b); class Program { static int Plus(int a, int b) { return a + b; } static void Main(string[] args) { Delelegate pd1 = Plus; Delelegate pd2 = delegate (int a, int b) { return a / b; }; Console.WriteLine(pd1(5, 10)); Console.WriteLine(pd2(10, 5)); } } public class App { public App() { //1. 기존 메서드 지정 Action action1 = Print; action1("1.기본 메서드 지정 방식"); //2. 무명 메서드 ..
2021.03.23 -
0317 interface+abstract+stack+queue
public class Censored:Abnormality,IEscapable,ISpawnBaby { public Censored() { } public void Escapable() { Console.WriteLine("검열삭제가 격리실을 벗어났습니다."); } public override void Attack() { Console.WriteLine("검열삭제가 공격합니다."); } public void SpawnBaby() { Console.WriteLine("검열삭제가 새끼를 깝니다."); } } public class SilentOrchestra:Abnormality,IEscapable { public SilentOrchestra() { } public void Escapable() { Cons..
2021.03.17 -
0316 컬랙션 과제
public App() { Console.WriteLine("App"); //ArrayList 변수 선언 ArrayList list; //ArrayList객체 생성 list = new ArrayList(); //ArrayList에 요소 추가 list.Add("나무꾼의 집"); list.Add("뚝딱 대장간"); list.Add("젤리빈 농장"); list.Add("각설탕 채석장"); list.Add("설탕몽땅 젤리빈"); //ArrayList의 길이 출력 Console.WriteLine("리스트의 길이 출력==============="); Console.WriteLine(list.Count); //ArrayList의 모든 요소 출력 Console.WriteLine("리스트의 요소 출력===========..
2021.03.17 -
0314 클래스와 메서드
ref static void Main(string[] args) { int x = 10; //초기화 꼭 해야함 PassByValue(x); Console.WriteLine(x); // x = 10 ← 메서드에서 변경된 부분이 호출 함수에서 반영되지 않음 PassByReference(ref x); Console.WriteLine(x); // x = 13 } static void PassByValue(int a) { a += 3; } static void PassByReference(ref int a) { a += 3; } 1. 오버로딩 객체 지향 언어에선 메소드의 전달인자의 종류와 개수를 기반으로 호출하기에 문제 발생x 겉모습은 같은 이름의 메소드라도 전달인자가 다르면 다른 메소드로 취급한다. public..
2021.03.15 -
0311 Class+맴버 변수+메서드 호출 연습
public class Carrigon { public string name; public float hp; public Carrigon() { Console.WriteLine("캐리건이 생성되었습니다."); } public void SetName(string name) { this.name = name; Console.WriteLine("캐리건의 아이디가 {0}으로 설정되었습니다.", this.name); } public void Hp(float hp) { this.hp = hp; Console.WriteLine("캐리건의 데미지가{0}로 설정되었습니다.",this.hp); } class Program { //캐리건 클래스 호출 후 메서드 호출 static void Main(string[] args) ..
2021.03.11