What is null in c#, java?

2020-02-09 07:51发布

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 question is rather - how it's done

标签: c# java null
9条回答
老娘就宠你
2楼-- · 2020-02-09 08:35

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.

查看更多
Deceive 欺骗
3楼-- · 2020-02-09 08:37

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).

查看更多
forever°为你锁心
4楼-- · 2020-02-09 08:37

It is a special reference ( to differentiate it from 0 ) which point to nothing.

查看更多
登录 后发表回答