C#C
C#4y ago
Hugh

❔ Generics with different input and output type

I'm writing a generic at the moment which it something like this:
T GetSomething<T, U>(U InputValues)

When I'm calling it, is there any way to only specify T without specifying U (as this can be inferred from the argument being passed in).

Ideally I'd like to be able to type something like:

MyInputType inputValues;
MyType result = GetSomething<MyType>(inputValues);


rather than

MyInputType inputValues;
MyType result = GetSomething<MyType, MyInputType>(inputValues);


Is something like this possible at all?
Was this page helpful?