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();
            }
        }
    }
  • 相关阅读:
    C# Func的同步、异步调用
    C#以管理员身份运行程序
    C# 代码编程规范
    C# DES加密解密
    C# MD5加密
    EntityFramework查询--联合查询(Join,GroupJoin)
    C# 图片和Base64之间的转换
    php 验证身份证号
    Vue环境搭建
    PHP 3种方法实现采集网站数据
  • 原文地址:https://www.cnblogs.com/sulong/p/4797756.html
Copyright © 2011-2022 走看看