-
03/24 callback 연습C#/수업내용 2021. 3. 24. 12:32
Program.cs
using System; namespace Study07 { class Program { static void Main(string[] args) { Console.WriteLine("Main"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace Study07 { public class Barracks { public Barracks() { Console.WriteLine("배럭스가 생성되었습니다."); } public void CreateUnit(eUnitType unitType, Action<Unit> callback) { for(int i = 0; i<=10; i++) { Thread.Sleep(500); Console.WriteLine(i * 10+"%"); } Console.WriteLine("{0}이 생성되었습니다.", unitType); callback(new Unit(unitType)); } } public enum eUnitType { MARINE, FIREBAT, GHOST, MEDIC } public class Unit { public eUnitType UnitType { get; set; } public Unit(eUnitType unitType) { UnitType = unitType; } } public class App { //생성자 public App() { Console.WriteLine("App"); Barracks barracks = new Barracks(); barracks.CreateUnit(eUnitType.MARINE, (unit) => { Console.WriteLine(unit); //Mainre }); } } }
'C# > 수업내용' 카테고리의 다른 글
03/24 event연습 (0) 2021.03.24 03/24 SortedList, IComparable 연습 (0) 2021.03.24 03/24 델리게이트 연습 (0) 2021.03.24 03/24 Event연습 (0) 2021.03.24 03/23 수업내용 메모 (0) 2021.03.23