• 委托小例子两个


    示例一:

    class Program

        {

    static void Main(string[] args)

            {

    string res= new Program().ShowMsg();

    Console.WriteLine(res);

    Console.Read();

            }

    private delegate string DelegateMsg();

    private string ShowMsg()

            {

    DelegateMsg dmsg = GetMsg;

    return dmsg.Invoke();

            }

    public string GetMsg()

            {

    return DateTime.Now.Ticks.ToString();

            }

        }

    示例二:

    class Program

        {

    static void Main(string[] args)

            {

    var res = new Program().Show();

    Console.WriteLine(res);

    Console.Read();

            }

    public string Show()

            {

    MsgService msgService = new MsgService();

                msgService.delegateMsg += new MsgService.DelegateMsg(msgService.ShowMsg);

                msgService.delegateMsg += new MsgService.DelegateMsg(msgService.GetMsg);

    if (msgService.delegateMsg != null)

                {

                    msgService.delegateMsg.Invoke();

                }

    return "";

            }

    public class MsgService

            {

    public delegate string DelegateMsg();

    public DelegateMsg delegateMsg;

    public string ShowMsg()

                {

    DelegateMsg dmsg = GetMsg;

    var res = dmsg.Invoke();

    Console.WriteLine(res);

    return res;

                }

    public string GetMsg()

                {

    var res = DateTime.Now.Ticks.ToString();

    Console.WriteLine(res);

    return res;

                }

            }

        }

  • 相关阅读:
    Mysql之锁、事务绝版详解干货!
    SSL基础知识(比较清楚)
    数字证书使用流程指南
    HTTPS与SSL
    IIS 6.0 Web园(Web Garden)
    验证数字可以有千分符可以有0个1个小数点小数点后输入后四舍五入保留两位(写个js验证真费劲)
    线程安全
    利用SSL给IIS加把锁(转)
    弹出div后其它不能操作(小技巧)
    关于反射
  • 原文地址:https://www.cnblogs.com/jzb-dev/p/3484495.html
Copyright © 2020-2023  润新知