zoukankan      html  css  js  c++  java
  • C#委托示例

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace ExDelegate
    {
        delegate void PrintFunction();
        delegate void MyDel(ref int x);
        class Test
        {
            public void print1()
            {
                Console.WriteLine("Print1---instance");
            }
            public static void print2()
            {
                Console.WriteLine("Print2---static");
            }
        }
        class MyClass
        {
            public void Add2(ref int x)
            {
                x += 2;
            }
            public void Add3(ref int x)
            {
                x += 3;
            }
            static void Main(string[] args)
            {
                MyClass mc = new MyClass();
                MyDel md = mc.Add2;
                md += mc.Add3;
                int x = 5;
                md(ref x);
                Console.WriteLine("Value:{0}",x);
                Test t1 = new Test();
                PrintFunction pf;
                pf = t1.print1;
                pf += Test.print2;
                if (null != pf)
                {
                    pf();
                }
                else
                {
                    Console.WriteLine("Delegate is empty");
                }
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    DOM getElementById
    百度之星2014
    游艇租借
    2014年acm亚洲区域赛·鞍山站
    UVALive 4255 Guess
    UVA 10054 The Necklace
    UVA 10047 The Monocycle
    UVA 11624 Fire!
    第九届黑龙江省赛
    剑指offer系列31-----二叉树的下一个节点
  • 原文地址:https://www.cnblogs.com/sulong/p/4797756.html
Copyright © 2011-2022 走看看