-
03/24 Event연습C#/수업내용 2021. 3. 24. 09:53
Program.cs
using System; namespace Study07 { class Program { static void Main(string[] args) { Console.WriteLine("Program"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace Study07 { public class DoorEventArgs : EventArgs { public DateTime Time { get; set; } public DoorEventArgs() { Time = DateTime.Now; } } public class Door { public event EventHandler alertDoor; public void Open() { Console.WriteLine("문을 엽니다."); alertDoor(this, new DoorEventArgs()); } } public class App { //생성자 public App() { Console.WriteLine("App"); Door door = new Door(); door.alertDoor += AlertOpen; door.Open(); } private void AlertOpen(Object obj, EventArgs args) { DoorEventArgs doorEventArgs = (DoorEventArgs)args; Console.WriteLine("문이 열렸습니다. 일시 : {0}", doorEventArgs.Time); } } }
'C# > 수업내용' 카테고리의 다른 글
03/24 callback 연습 (0) 2021.03.24 03/24 델리게이트 연습 (0) 2021.03.24 03/23 수업내용 메모 (0) 2021.03.23 03/23 List<T>.Find(Predicate<T>) 메서드 연습 (0) 2021.03.23 03/23 Linq Where 연습 (0) 2021.03.23