C# 委托的使用(指向函数的指针)

来源:互联网 发布:文职将军知乎 编辑:程序博客网 时间:2024/05/14 17:37
using System;namespace ConsoleApplication19{    class Program //so easy    {        public delegate void Del(string message);        public static void DelegateMethod(string message)        {            Console.WriteLine(message);        }        public static void MethodWithCallback(int param1, int param2, Del callback)        {            callback("The number is: " + (param1 + param2).ToString());        }        static void Main(string[] args)        {            // Instantiate the delegate.            Del handler = DelegateMethod;            // Call the delegate.            //handler("Hello World");            MethodWithCallback(1, 2, handler);        }    }}

0 0
原创粉丝点击