zoukankan      html  css  js  c++  java
  • 委托的4种写法

    委托1:
    
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplicartion2
    {
        public delegate void G();//定义一个委托
        public partial class Form1 : Form
        {
    
            public static void Main(string[] args)//调用方法
            {
                G g = new G(W);
                g();
                Console.ReadKey();
            }
            private static void W()//写了一个方法
            {
                Console.Write("你好");
            }
        }
    }
    
    带参数的委托
    namespace WindowsFormsApplicartion2
    {
        public delegate void G(string a,string b);
        public partial class Form1 : Form
        {
    
            public static void Main(string[] args)
            {
                G g = new G(W);
                g("你好","再见");
                Console.ReadKey();
            }
            private static void W(string a,string b)//方法
            {
                Console.Write(a+b);
            }
        }
    }
    
    
    
    另一个写法
    namespace WindowsFormsApplicartion2
    {
        public delegate void G(string a,string b);
        public partial class Form1 : Form
        {
    
            public static void Main(string[] args)
            {
                G g = new G(delegate {
                    Console.WriteLine("你好");
                
                });
               
            }
    
    另一方法的带参数的委托
    
    namespace WindowsFormsApplicartion2
    {
        public delegate void G(string a,string b);
        public partial class Form1 : Form
        {
    
            public static void Main(string[] args)
            {
                G g = new G(delegate(string a, string b) { Console.WriteLine(a + b); });
                g("你好","再见");
                Console.ReadLine();
                //g("你好","再见");
                //Console.ReadKey();
            }
  • 相关阅读:
    UVA 10391 STL容器的使用
    UVA 10763
    UVA 10935
    UVA 洪水
    UVA 1594 set 里面放queue
    关于STL 容器的嵌套使用, 小试牛刀
    丑数 UVA 136
    UVA 1368 DNA
    antd 上传文件控件使用方法(坑)
    mysql查询一条工单时间需要10秒。优化sql语句得以解决。
  • 原文地址:https://www.cnblogs.com/w-wz/p/4620215.html
Copyright © 2011-2022 走看看