在一行中声明和定义委托(不使用Action / Func)

时间:2016-09-04 10:57:46

标签: c# delegates

有没有办法缩短以下内容:

public class Test
{
    /* declares a delegate type (named MyDelegateType) which has a single parameter of 
        type float and doesn't return anything. */
    public delegate void MyDelegateType(float f); 

    /* defines a reference to an object of type MyDelegateType */                                                
    private MyDelegateType MyDelegateRef;

    ... // say we have a Property to set and get MyDelegateRef, and a method
        // for executing its target
}

分成一行,不使用Action / Func类型?

我要求了解这是否与我们在C ++(或C)中使用函数指针所做的相同:

class Test
{
   /* defines a pointer (named MyFP) to a function with a single 
      parameter of type float, and doesn't return anything */
   void(*MyFP)(float); 

   ... // say we have a Setter & Getter functions, and an Execute 
       // function for executing MyFP
}

1 个答案:

答案 0 :(得分:1)

不,这就是框架中包含Action<T>Func<T>的原因。

相关问题