Delegate(대리자)
delegate는 명명된 메서드나 익명 메서드를 캡슐화하는 데 사용할 수 있는 참조 형식입니다. 대리자는 C++의 함수 포인터와 비슷하지만 형식 안전성과 보안성을 제공한다는 점이 다릅니다
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DeclareaDelegate
{
class MathClass
{
public void MultiplyNumber(int m, double n)
{
Console.WriteLine(m * n + "");
}
}
delegate void del(int i,double j);
class Program
{
static void Main(string[] args)
{
MathClass m = new MathClass();
del d = m.MultiplyNumber;
Console.WriteLine("Invoking the delegate using 'MultiplyNumbers':");
for (int i = 1; i <= 5; i++)
{
d(i, 2);
}
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}
'Programing > C#&.Net' 카테고리의 다른 글
형식 메타데이터 (0) | 2016.11.30 |
---|---|
c# 프로그램 연습 (0) | 2016.11.30 |
dll만들기 명령 프롬프트 사용 (0) | 2016.11.30 |
c# 기초 (0) | 2016.11.30 |
마샬링(marshalling) (0) | 2016.11.30 |