zoukankan      html  css  js  c++  java
  • 简单的委托示例

    单委托:

        

     1 using System;
     2 namespace test
     3 {
     4     public delegate void saydel(string name);
     5     class Hello
     6         {
     7             public void sc(string name)
     8             {
     9                 string str="你好,"+name;
    10                 Console.WriteLine(str);
    11             }
    12             public void se(string name)
    13             {
    14                 string str="hello,"+name;
    15                 Console.WriteLine(str);
    16             }
    17             public void DoWork(string name,saydel ms)
    18             {
    19                 ms(name);
    20             }
    21             static void Main()
    22                 {
    23                     Hello h=new Hello();
    24                     h.DoWork("user",h.se);
    25                     h.DoWork("user",h.sc);
    26                 }
    27         }
    28 }
    29 

    多播委托:

     1 using System;
     2 namespace test
     3 {
     4     public delegate void saydel(string name);
     5     class Hello
     6         {
     7             public void sc(string name)
     8             {
     9                 string str="你好,"+name;
    10                 Console.WriteLine(str);
    11             }
    12             public void se(string name)
    13             {
    14                 string str="hello,"+name;
    15                 Console.WriteLine(str);
    16             }
    17             public void DoWork(string name,saydel ms)
    18             {
    19                 ms(name);
    20             }
    21             static void Main()
    22                 {
    23                     Hello h=new Hello();
    24                     saydel deg=h.sc;
    25                     deg+=h.se;
    26                     h.DoWork("user",deg);
    27                 }
    28         }
    29 }
    30 
  • 相关阅读:
    一致性哈希算法(c#版)
    制作Docker镜像的两种方式
    AWS AutoScaling的一个ScaleDown策略问题以及解决方法
    在CentOS6.6上以replSet方式部署MongoDB集群
    在Docker中安装和部署MongoDB集群
    为Docker容器设置静态IP
    CSS动画的性能分析和浏览器GPU加速
    spark日志配置及问题排查方式。
    Structure Streaming和spark streaming原生API访问HDFS文件数据对比
    SQL On Streaming
  • 原文地址:https://www.cnblogs.com/xpxu/p/1701566.html
Copyright © 2011-2022 走看看