zoukankan      html  css  js  c++  java
  • 委托小例子两个

    示例一:

    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;

                }

            }

        }

  • 相关阅读:
    Angular
    linux mysql 5.7.25 安裝
    J2CACHE 两级缓存框架
    MYSQL 事务测试
    安装配置ftp服务器
    使用docker 安装 GITLIB
    Elastic serarch 安装
    centos firewalld 基本操作【转】
    KAFKA 监控管理界面 KAFKA EAGLE 安装
    redis 的一主二从三哨兵模式
  • 原文地址:https://www.cnblogs.com/jzb-dev/p/3484495.html
Copyright © 2011-2022 走看看