第七章 代理(1)
一、代理要聲明
二、代理使用步驟
- 聲明代理
- 初始化代理(使用 實例的方法名 作為參數)
- 使用代理
代碼示例:
/*C7.1.2*/ using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace C7._1._2 {class Program{//聲明代理private delegate string getStr();static void Main(string[] args){int x = 10;getStr testDeleMethod = new getStr(x.ToString ); //初始化的參數是 實例的一個方法名Console.WriteLine("Delegate Method Test: the string type of x is " + testDeleMethod());Console.ReadLine();}}}
?