Why does “Func test = value ? F: F” not compile?

后端 未结 2 1774
借酒劲吻你
借酒劲吻你 2020-12-06 09:56

I have seen similar questions to this, but they involve different types so I think this is a new question.

Consider the following code:

public void T         


        
2条回答
  •  旧时难觅i
    2020-12-06 10:12

    var test = value ? (Action)Func: (Action)Func;
    

    Actually, type of method is expressed by delegate it matches. System.Action that i used to cast methods to, is the delegate with signature returning void and taking no parameters - it matches your Func() method. And now your test will know that it is type of System.Action. Delegates are something like interfaces for methods. Take a look at http://msdn.microsoft.com/en-us/library/ms173171(v=vs.80).aspx

提交回复
热议问题