DEV Community


Discussion on: Universally quantified types in C#

hanpari profile image
Pavel Morava

You answered your own question as soon as you've realized you could not give two different T under one scope. Just declare your getWeight somewhere else like extension method, calculate weights and sum them. Or you can constraint your Type T to some ad-hoc interface.

T doesn't mean here for all Ts. It means whenever T appears, it is type of T. You can distinguish two different types by but I doubt it is going to be helpful.

shimmer profile image
Brian Berns Author • Edited

One of the requirements is that you have to pass a generic getWeight to SumWeights somehow. Imagine that there are multiple different implementations of getWeight that all have the same type signature. How do you tell SumWeights which version to use?