HappyWeasel

C# - delegate 본문

Basic/ C# (.NET)

C# - delegate

HappyWeasel 2019. 4. 29. 16:40

출처: https://nowonbun.tistory.com/117?category=507214 [명월 일지]

 

자기 자신이 선언되지 않고 다른 함수를 참조하여 실행하는 형태

using System;
using System.Collections.Generic;
using System.Text;
namespace delegate_20120918
{
	class Program
	{
		static void Main(string[] args)
		{
			new Program();
		}
		//델리 게이트 선언
		delegate void Ex_Delegate(String str);
		//대리 실행 함수 선언
		// 반환자와 파라미터가 델리 게이트와 일치한다.
		public void Ex_Method(String str)
		{
			Console.WriteLine(str);
		}
		public Program()
		{
			//델리 게이트에 메소드를 넣는다.
			Ex_Delegate ED = new Ex_Delegate(Ex_Method);
			//델리 게이트 실행
			ED("Hello World");
			Console.WriteLine("Press any key...");
			Console.ReadLine();
		}
	}
}

'Basic > C# (.NET)' 카테고리의 다른 글

C# - SQLite 연동하기  (0) 2019.05.09
C# - Excel 연동하기  (0) 2019.05.08
C# - 구조체 (Struct)  (0) 2019.04.29
C# - Form 창 크기 잠금  (0) 2019.04.24
C# - 암호화 (SHA256)  (0) 2019.04.22
Comments