Why is wrong this inline if?
.net, c#, cls, exception, iif
Solution
Converting comment to an answer:
From MSDN:
Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other.
?: Operator
As `int?` cannot be converted to an exception, and throw is not an expression, hence the error within your code.
Problem
If have the following statement: ``` return this.revision.HasValue ? this.revision : throw new InvalidOperationException(); ``` I thought it would compile as the throw is breaking the normal flow and it shouldn't be a problem to not return a value but it does not build. Is there a way to put right this statement or why is this not allowed? Thanks. EDIT: this.revision is int? and the method returns int. EDIT 2: if I have this method ``` public int Test() { throw new Exception(); } ``` The compiler does not complain about not returning a value, I expected the same thing from an inline if ... at least we know that can be done as it's already done in methods.