What's the difference between 'int?' and 'int' in C#?

后端 未结 7 1156
甜味超标
甜味超标 2020-12-02 17:44

I am 90% sure I saw this answer on stackoverflow before, in fact I had never seen the \"int?\" syntax before seeing it here, but no matter how I search I can\'t find the pre

7条回答
  •  自闭症患者
    2020-12-02 18:24

    int belongs to System.ValueType and cannot have null as a value. When dealing with databases or other types where the elements can have a null value, it might be useful to check if the element is null. That is when int? comes into play. int? is a nullable type which can have values ranging from -2147483648 to 2147483648 and null.

    Reference: https://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx

提交回复
热议问题