// 익명 메소드 구현하기
// 대리자의 메소드
class Program
{
delegate int Calculate(int a, int b);
static void Main(string[] args)
{
// 대리자 객체 생성
Calculate Calc;
// 해당 객체의 익명 메소드 생성 구문
Calc = delegate (int a, int b)
{
return a + b;
}; // 세미콜론주의
// 실행
Console.WriteLine(Calc(1, 3));
}
}
728x90
'C#' 카테고리의 다른 글
C# / 대리자 실습 - Delegate / event 구현 (0) | 2022.08.10 |
---|---|
C# / 대리자 실습 - Delegate / 익명 메소드로 버블 정렬 구현 (0) | 2022.08.10 |
C# / 대리자 실습 - 대리자 체인 DelegateChain / 체인 연산 (0) | 2022.08.10 |
C# / 대리자 실습 - Delegate / 정렬 메소드 구현 추가IComparable<T> 사용 (0) | 2022.08.10 |
C# / 대리자 실습 - Delegate / 버블 정렬을 위한 대리자 (0) | 2022.08.10 |
댓글