C#/수업 내용

C#/수업 내용

파일 로드 대리자 예제 2

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study10 { class App { //2. 대리자 형식 정의 delegate void MyDel(string contents); //생성자 public App() { //3. 대리자 변수 정의 //MyDel myDel; //4. 대리자 인스턴스 생성 (메서드 연결), 변수에 할당 //myDel = new MyDel(this.Print); this.LoadFile(null); //대리자 변수에 null값 허용 } private void LoadFile(MyDel myDel) { ..

C#/수업 내용

Cal 연습문제 (대리자)

App 클래스 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study10 { class App { //생성자 public App() { Calculator cal = new Calculator(); int sum = cal.Plus(1, 2); Console.WriteLine("sum: {0}", sum); //(불가능, Minus는 static 메서드) //static 메서드는 형식으로 접근 //int result = cal.Minus(5, 2); int result = Calculator.Minus(5, 2); Consol..

C#/수업 내용

오전 수업내용 : 대리자

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study10 { class App { //2.대리자정의 : 클래스안에다 한다. //주의사항 : 대리자 인스턴스에 연결한(할당할) 메서드의 시그니처와 동일해야한다. //메서드 정의부터 한 뒤 대리자 생성 delegate int MyDelegate(int a, int b); //생성자 public App() { //3. 변수정의 MyDelegate del; //3. 대리자 인스턴스화 del = new MyDelegate(Plus); //5. 대리자 호출 :대리자의 메서드 호출 int ..

C#/수업 내용

2023/01.10 문자열 형식 오전 수업내용

using System; using System.Collections; using System.Collections.Generic; namespace Study10 { class App { //생성자 public App() { //문자형식(Char) 변수 a를 정의 char a; //값을 할당할땐 작은 따옴표로 할당'' a = 'a'; //변수의 값을 출력 Console.WriteLine(a); Console.WriteLine(a++); //65+1 Console.WriteLine(a + 1); Console.WriteLine(a - 1); Console.WriteLine(a--); //문자 형식은 정수로 암시적 변환 가능 int b = (int)a; //명시적 int c = a; //암시적 string..

C#/수업 내용

메서드 오버라이딩

App단 using System; using System.Collections; using System.Collections.Generic; namespace Study09 { class App { public App() { Marine marine = new Marine(); Firebat firebat = new Firebat(); marine.Attack(); firebat.Attack(); } } } 테란 유닛 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study09 { class TerranUnit { //생성자 p..

C#/수업 내용

Queue 연습

using System; using System.Collections; using System.Collections.Generic; namespace Study09 { class App { public App() { //Qeueu인스턴스 생성 Queue q = new Queue(); //Add q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); //contains bool contains = q.Contains(3); Console.WriteLine(contains); //단일 요소 가져오기 int peek = q.Peek(); //확인 Console.WriteLine(peek); int num = q.Dequeue(); //제거 Remove Console.WriteLine(num..

C#/수업 내용

Stack 사용 연습

using System; using System.Collections; using System.Collections.Generic; namespace Study09 { class App { public App() { //컬렉션 생성 Stack weapons = new Stack(); Weapon weapon0 = new Weapon("장검"); //Add weapons.Push(weapon0); weapons.Push(new Weapon("단검")); Weapon peek = weapons.Peek(); //제거 안하고 젤 위에꺼 확인 Console.WriteLine(peek.Name); //단검 Console.WriteLine(weapons.Count); //2 //Contains bool contai..

C#/수업 내용

List사용 연습

using System; using System.Collections; using System.Collections.Generic; namespace Study09 { class App { public App() { Console.WriteLine("App생성자 입니다."); //list 인스턴스 생성 List armors = new List(); Armor armor0 = new Armor("투구"); Armor armor1 = new Armor("갑옷"); Armor armor2 = new Armor("어깨 방어구"); Armor armor3 = new Armor("무릎 방어구"); //Add armors.Add(armor0); armors.Add(armor1); armors.Add(armor2); ..

C#/수업 내용

오전 수업내용 : 일반화 메서드

using System; using System.Collections; namespace Study09 { class App { public App() { int[] arr0 = { 1, 2, 3 }; int[] arr1 = new int[3]; //{0, 0, 0} CopyArray(arr0, arr1); string[] arr2 = { "홍길동", "임꺽정", "장길산" }; string[] arr3 = new string[3]; CopyArray(arr2, arr3); Hero[] arr4 = { new Hero(), new Hero(), new Hero() }; Hero[] arr5 = new Hero[3]; CopyArray(arr4, arr5); //일반화 메서드 CopyArray(arr0, ..

C#/수업 내용

오전 수업내용 : 구조체

using System; using System.Collections; namespace Study09 { class App { ArrayList list; //변수 정의 Point3D point3D; //생성자 public App() { //Console.WriteLine(point3D); //선언만으로 인스턴스 생성가능 //pint3D = new Point3D(10,0,0); //Console.WriteLine(point3d); // new 키워드 사용 가능 point3D.x = 10; point3D.y = 10; point3D.z = 10; Point3D point3d2 = new Point3D(100, 200, 300); Point3D point3d3 = point3d2; point3d3.z = ..

Bueong_E
'C#/수업 내용' 카테고리의 글 목록 (2 Page)