DEV Community

loading...

Discussion on: Universally quantified types in C#

costinmanda profile image
Costin Manda

You can't pass a generic function as a parameter without having your own function be generic. Therefore you need to encapsulate it. Like in an interface. This would be the best design for your problem.

    interface IWeighter
    {
        int getWeight<T>(IList<T> list);
    }

But you want to pass a function as a parameter, so probably this ain't it. I have the feeling that whatever you're proposing will not sit well with me.

Thread Thread
shimmer profile image
Brian Berns Author

You got it. That interface is exactly what I'd suggest. You're still passing in the function, just with one level of indirection. It's a bit more verbose, but not too bad, I think. Nice work!