zoukankan      html  css  js  c++  java
  • 学习笔记c#委托

    简单委托实现步骤

    1,声明委托

    public delegate void pg(object sender,eventargs e);

    2,定义委托调用

    class Send

    {

      public event pg thePG;//定义委托实例

      public void onSend(eventargs e)

      {

        if(thePG != null)

        {//代理实例化,则执行代理

          thePG(this,e);

        }

      }//触发器

    }

    3,定义具体实现函数

    class MS

    {

      public MS(Send sd)

      {

        sd.thePG += new  pg(MSPG);

      }

      public void MSPG(object sender, eventargs e)

      {

        console.wrikteline(""who langh the last who wins. );

      }

    }

    4,当调用send.onSend时会执行代理函数,即MS.MSPG;

    可理解委托像一个指针,该例中指针指向MS.MSPG。所以调用指针就是调用MS.MSPG.

  • 相关阅读:
    《统计学习方法》
    《赤裸裸的统计学》
    a[i]=i++
    正态分布(normal distribution)
    可视化
    数据转换
    beLazy
    水到渠成
    数据过滤
    数据合并
  • 原文地址:https://www.cnblogs.com/maomaokuaile/p/2828021.html
Copyright © 2011-2022 走看看