Nullable ToString()

前端 未结 6 1920
清歌不尽
清歌不尽 2020-12-13 22:39

I see everywhere constructions like:

int? myVar = null;
string test = myVar.HasValue ? myVar.Value.ToString() : string.Empty;

Why not use

6条回答
  •  独厮守ぢ
    2020-12-13 23:21

    I think that many people have such checks because it is not a natural behavior of an object that can hold null value.

提交回复
热议问题