How is null represented in .NET

前端 未结 4 1910
南方客
南方客 2021-01-18 08:20

I was having a conversation with a co-worker and the subject of null came up. He was telling me that in .NET behind the scenes it is just a really small number. I always tho

4条回答
  •  情歌与酒
    2021-01-18 08:54

    It's 0.

    Snip from ldnull in ECMA-335 spec:

    It might be thought that ldnull is redundant: why not use ldc.i4.0 or ldc.i8.0 instead? The answer is that ldnull provides a size-agnostic null – analogous to an ldc.i instruction, which does not exist. However, even if CIL were to include an ldc.i instruction it would still benefit verification algorithms to retain the ldnull instruction because it makes type tracking easier.

提交回复
热议问题