Is it possible to use operator ?? and throw new Exception()?
问题 I have a number of methods doing next: var result = command.ExecuteScalar() as Int32?; if(result.HasValue) { return result.Value; } else { throw new Exception(); // just an example, in my code I throw my own exception } I wish I could use operator ?? like this: return command.ExecuteScalar() as Int32? ?? throw new Exception(); but it generates a compilation error. Is it possible to rewrite my code or there is only one way to do that? 回答1: For C# 7 In C# 7, throw becomes an expression, so it's