c# 기초구문 업데이트 완료
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using static MyClass;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
MyClass cls = new();
|
||||
cls.OnFinished += new OnFinishedEventHandler(Cls_OnFinished);
|
||||
cls.OnFinished += Cls_OnFinished;
|
||||
|
||||
//Annonymous Method 사용
|
||||
cls.OnFinished2 += delegate (object? sender, EventArgs eventArgs)
|
||||
{
|
||||
Console.WriteLine("Finished");
|
||||
};
|
||||
|
||||
//Lambda 식 사용, 무명메서드를 대신할 수 있다.
|
||||
//(입력 파라미터) => { 실행문장 블럭 };
|
||||
cls.OnFinished += (sender, eventArgs) => { Console.WriteLine("Finished"); };
|
||||
|
||||
}
|
||||
|
||||
private static void Cls_OnFinished(object? sender, EventArgs eventArgs)
|
||||
{
|
||||
Console.WriteLine("Finished");
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass
|
||||
{
|
||||
//EventHandler를 delegate로 구현
|
||||
public delegate void OnFinishedEventHandler(object? sender, EventArgs eventArgs);
|
||||
public event OnFinishedEventHandler? OnFinished;
|
||||
|
||||
public EventHandler<EventArgs>? OnFinished2;
|
||||
|
||||
public void Run(int complexity)
|
||||
{
|
||||
Thread.Sleep(complexity);
|
||||
OnFinished?.Invoke(this, EventArgs.Empty);
|
||||
OnFinished2?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user