As in the other answer, it is quite normal for your variable to contain null- this is about a reference to the variable null, and this cannot be in C # or most other managed languages ββfor this.
, Interlocked.CompareExchange a NullReferenceException, IL. , , :
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 3
.locals init ([0] int32& x)
ldloc.0
ldc.i4.1
ldc.i4.2
call int32 [mscorlib]System.Threading.Interlocked::CompareExchange(
int32&, int32, int32)
pop
ret
}
, NullReferenceException . Interlocked.CompareExchange, JIT lock cmpxchg.
@Sean, , NullReferenceException, ref out. , Int32.TryParse , NRE, " result is null", . , , .