What is null in c#, java?

后端 未结 9 1168
挽巷
挽巷 2020-12-15 23:09

Like... is it 0 like in C++? Or is it some \"special\" object? Or maybe something totally different?

-- EDIT --

I do know what it is, the

相关标签:
9条回答
  • 2020-12-15 23:48

    null is a "reference" to nothing, so it points to literally nothing.

    Additional info: A C# reference type can point to null (i.e.: nothing), a value type like int cannot point to null, although a valuetype can be used in the Nullable generic reference type.

    0 讨论(0)
  • 2020-12-15 23:48

    Null is literally nothing. Some languages like PHP will equate null to 0, false, empty string, etc. under certain circumstances. Java and C# are strongly typed languages. Therefore none of those "helpful" implicit conversions take place. So null is literally null or nothing. Null is only equal to null. No other comparison will return true.

    0 讨论(0)
  • 2020-12-15 23:58

    From Microsoft MDSN:

    The null keyword is a literal that represents a null reference, one that does not refer to any object. null is the default value of reference-type variables. Ordinary value types cannot be null. However, C# 2.0 introduced nullable value types. See Nullable Types (C# Programming Guide).

    0 讨论(0)
提交回复
热议问题