I have a choice between two statically defined converters, and I want to use a ternary expression to make the choice:
Func<Input, Output> converter = useConverter1
? MyConverter.Converter1
: MyConverter.Converter2;
The compiler will not accept this expression. It fails with a message saying "There is no implicit conversion between 'method group' and 'method group'".
The structure of MyConverter
is
public static class MyConverter
{
public static Output Converter1(Input input)
{
....
}
public static Output Converter1(Input input)
{
....
}
}
Can I work around this without an if-else statement?