首页 > 其他 > 详细

最简单易懂的委托例子

时间:2014-11-13 18:32:56      阅读:222      评论:0      收藏:0      [点我收藏+]
 1 class Program
 2 {
 3     delegate double ProcessDelegate(double param1, double param2);
 4      
 5     static double Multiply(double param1, double param2)
 6     {
 7         return param1*param2;
 8     }
 9  
10     static double Divide(double param1, double param2)
11     {
12         return param1/param2;
13     }
14  
15     static void Main(string[] args)
16     {
17         ProcessDelegate process;
18         Console.WriteLine("Enter 2 number separated with a comma:");
19         string input = Console.ReadLine();
20         int commaPos = input.IndexOf(,);
21         double param1 = Convert.ToDouble(input.Substring(0,commaPos));
22         double param2 = Convert.ToDouble(input.Substring(commaPas+1,input.Length - commaPos-1));
23         Console.WriteLine("Enter M or D:");
24         input = Console>readLine();
25         if(input == "M")
26             process = new ProcessDelegate(Multiply);
27         else
28             process = new ProcessDelegate(Divide);
29         Console.WriteLine("Result:{0}",process(param1 ,param2 ));
30     }
31 }

 

最简单易懂的委托例子

原文:http://www.cnblogs.com/mvv118/p/4095513.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!