This is simply because ?
and &
are overloaded and can also indicate a conditional operator and "address of" respectively. The compiler needs to know what you mean. This fixes it:
var getaccess = (val is int?) & result;
The compiler message isn't entirely clear, but gives us the clues:
CS0214 Pointers and fixed size buffers may only be used in an unsafe
(which is from the & result
)
CS1003 Syntax error, ':' expected
(which is from the ?
)
and:
CS1525 Invalid expression term ';'
(which is also from the ?
because it expects a : {value if false}
expression before the next semicolon)
Basically, without the parentheses it thinks you mean:
var getaccess = (val is int) ? (&result)
(with a missing expression for what to do if val
is not an int
)