• 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();
            }
        }
    }
  • 相关阅读:
    为什么写技术博客对新人如此重要?
    Javascript经典正则表达式
    关于读书的那些事,其实我一直...没有行动
    dede织梦CMS文件夹目录结构
    jQ初体验,^_^
    vi/vim 基本使用方法
    (X)HTML Strict 下的嵌套规则
    KISS保持简单:纪念丹尼斯·里奇
    关于jQuery性能优化
    编码规范CSSHTML 摘自kissyui
  • 原文地址:https://www.cnblogs.com/sulong/p/4797756.html
Copyright © 2020-2023  润新知