c#基础语法之 解读delegate create by lee

首先自己给委托下人地址 定义为 be defined as

 他其实是在求函数的入口地址,并且带标记,标记他是一个函数入口地址,举例说明如下,欢迎大家与我讨论。

代码

        
        
static public void Main()
        {
            MyClass p 
= new MyClass();

            p.InstanceMethod(); 
//直接调用的方式
            MyClass.StaticMethod(); //直接调用的方式



            
// Map the delegate to the instance method:
            MyDelegate d = new MyDelegate(p.InstanceMethod);
            d(); 
//以委托为中介,进行转换,进而可以函数 作函数的参数传递函数
       
            
// Map to the static method:
            d = new MyDelegate(MyClass.StaticMethod);
            d();  
//以委托为中介,进行转换,进而可以函数 作函数的参数传递函数

           
        }
    }


    
// delegate declaration
    delegate void MyDelegate();

    
public class MyClass
    {
        
public void InstanceMethod()
        {
            Console.WriteLine(
"A message from the instance method.");
        }

        
static public void StaticMethod()
        {
            Console.WriteLine(
"A message from the static method.");
        }
    }

这样你就能利用他的这个参数作为函数的 参数 来传递函数了,举例说明如下:

原文地址:https://www.cnblogs.com/chenli0513/p/1887316.html