委托应用

 


1
using System; 2 3 namespace DelegateEvents 4 { 5 public delegate string Mydel(string Mystring);//定义一个委托,和类同级 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 Tostring To = new Tostring(); 11 12 Mydel del=new Mydel(To.Tstring);//实例化委托并赋值 13 Console.WriteLine(del("123"));//实例化委托并赋值 14 Console.ReadKey(); 15 } 16 } 17 class Tostring 18 { 19 public string Tstring(string i)//定义一个方法实现委托参数功能 返回值类型,参数类型与之匹配 20 { 21 return i+"456"; 22 //Console.WriteLine(i); 23 } 24 } 25 }

猜你喜欢

转载自www.cnblogs.com/Maxs/p/9156977.html