How can I pass in a func with a generic type parameter?

后端 未结 4 1785
死守一世寂寞
死守一世寂寞 2020-12-01 17:59

I like to send a generic type converter function to a method but I can\'t figure out how to do it.

Here\'s invalid syntax that explains what I like to achieve, the p

4条回答
  •  难免孤独
    2020-12-01 18:26

    You need to make SomeUtility generic as well. Doing this and fixing the syntax gives:

    public void SomeUtility(Func converter)
    {
        var myType = converter("foo");
    }
    

提交回复
热议问题