Func delegate with no return type

前端 未结 7 1138
温柔的废话
温柔的废话 2020-12-02 03:54

All of the Func delegates return a value. What are the .NET delegates that can be used with methods that return void?

7条回答
  •  有刺的猬
    2020-12-02 04:40

    All Func delegates return something; all the Action delegates return void.

    Func takes no arguments and returns TResult:

    public delegate TResult Func()
    

    Action takes one argument and does not return a value:

    public delegate void Action(T obj)
    

    Action is the simplest, 'bare' delegate:

    public delegate void Action()
    

    There's also Func and Action (and others up to 16 arguments). All of these (except for Action) are new to .NET 3.5 (defined in System.Core).

提交回复
热议问题