Is there any difference between myNullableLong.HasValue and myNullableLong != null?

前端 未结 3 483
清歌不尽
清歌不尽 2020-12-29 01:29

When I have a nullable long, for example, is there any difference between

myNullableLong.HasValue 

and

myNullableLong !=          


        
3条回答
  •  盖世英雄少女心
    2020-12-29 02:06

    No.

    The C# compiler has built-in support for Nullable and will turn equality operations involving null into calls to the struct's members.

    n != null and n.HasValue will both compile to identical IL.

提交回复
热议问题