Inferring generic types with functional composition

前端 未结 4 1617
猫巷女王i
猫巷女王i 2021-01-05 18:04

Suppose I want to implement a functional composition, like this:

    public Func Compose(Func f, Func g)
    {
            


        
4条回答
  •  梦毁少年i
    2021-01-05 18:31

    You could pass Compose the parameter too, and have it actually evaluate the function; it should be able to infer the parameter type in that case. (You might need to still specify the return type, though.)

    Other than that, no, there's no way to infer things like this in C#.

提交回复
热议问题