개인 필기
멀티캐스트 대리자 예시
EasyCastleT
2023. 7. 27. 12:53
대리자를 결합하는 방법(멀티캐스트 대리자) - C# 프로그래밍 가이드
대리자를 결합하여 멀티캐스트 대리자를 만드는 방법을 알아봅니다. 코드 예제를 살펴보고 사용 가능한 추가 리소스를 확인합니다.
learn.microsoft.com
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
//using 지시문을 사용하면 네임스페이스에 정의된 형식을 해당 형식의 정규화된 네임스페이스를 지정하지 않고도 사용할 수 있습니다.
namespace LearnDotnet
{
//형식 정의
public class App
{
delegate void CunstomCallback(string s);
public App()
{
//여러 개의 대리자 정의
CunstomCallback hiDel, byeDel, multiDel, multiMinusHiDel;
//대리자 instance + 메서드 연결
hiDel = Hello;
byeDel = GoodBye;
multiDel = hiDel + byeDel;
multiMinusHiDel = multiDel - hiDel;
//출력
Console.WriteLine("대리자 hiDel:");
hiDel("A");
// Hello A!
Console.WriteLine("대리자 byeDel:");
byeDel("B");
//Good Bye, B!
Console.WriteLine("대리자 multiDel:");
multiDel("C");
//Hello C!
//Good Bye, C!
Console.WriteLine("대리자 multiMinusHiDel:");
multiMinusHiDel("D");
//Good Bye, D!
}
static void Hello(string s)
{
Console.WriteLine("Hello, {0}!", s);
}
static void GoodBye(string s)
{
Console.WriteLine("Good Bye, {0}!", s);
}
}
}