I've resolved numerous fights with C# not being able to resolve two lambdas in a conditional expression used to initialize a var. However today I faced what was seemingly a pretty easy and straight-forward pair of lambdas which I could not fight the compiler into accepting as the two results on a conditional expression. The compiler had no problem with them separately using an if-then-else construct instead.
Thus I decided to reduce the code down to as bare minimum as possible to show the problem, and discovered I could reduce it to pretty rock bottom and still get the error.
The compiler is issuing the usual error:
CS0173 Type of conditional expression cannot be determined because there is no implicit conversion between 'lambda expression' and 'lambda expression'
The following code is three examples of pretty rock-bottom code that still generates the error. The first line (test1) being what should be reasonably usable enough. The other lines being efforts to clarify through precedence and explicit typing.
Considering I have successfully used conditionals to select between two somewhat more complex (although not very complex) lambdas before, I was surprised to discover these extremely simple examples don't work.
Anybody know what's going on here?
In my case it's a C# UWP project set to build using C# 7.3. Visual Studio is not reporting any pending updates.
Func<int, int> test1 = true ? (a) => 0 : (a) => 0;
Func<int, int> test2 = true ? ((int a) => (int)0) : ((int a) => (int)0);
Func<int, int> test3 = true ? ((int a) => { return (int)0; }) : ((int a) => { return (int)0; });