Creating a delegate type inside a method

后端 未结 4 1437
轻奢々
轻奢々 2020-12-29 05:38

I want to create a delegate type in C# inside a method for the purpose of creating Anonymous methods.

For example:

public void MyMethod(){
   delegat         


        
4条回答
  •  盖世英雄少女心
    2020-12-29 06:05

    What about this:

    static void Main(string[] args)
    {
        Expression> exFunc = (a, b) => a + b;
        var lambda = exFunc as LambdaExpression;
        Delegate del = exFunc.Compile();
        Console.WriteLine(del.DynamicInvoke(2, 2));
    }
    

提交回复
热议问题