When declaring a variable with var you must immediately assign a value to it, so the compiler can know its type.
Although you could make a compiler smart enough to find the first use, the C # compiler does not understand this code.
You can use:
var someVar = cond ? someThing : someThingElse; if (cond) {
If someThing and someThingElse are of the same type. I think it is clearer to understand the possible values ββof someVar, but you double check the cond.
source share