Does null inherit from an object as well as in C #?

Does a null object inherit from an object also in C #?

Where does null define itself?

+6
c #
source share
6 answers

null has a "null type" that inherits from the object.

See ECMA-334 11.2.7

+2
source share

Does a null object inherit from an object also in C #?

Unlike other systems, null not defined in terms of a class or instance. On the contrary, this means the absence of any instance, and it has no type. It is implicitly converted to any reference type appropriate to the context. The greatest conversion (i.e., when the other cannot be deduced) refers to object . But still, null usually not of type object .

+10
source share

null not an object - it is a language keyword that means there is no reference to the object.

+6
source share

Where does null define itself?

null is a keyword. null is not a type.

There are two kinds of variables, each of which has its own set of zeroing rules.

Reference Type Variables

The variable is set and can refer to instances of the same or different types.

 //The reference type is System.Object and // the instance type is System.String object s = "123"; 

With reference variable types, null indicates no instance.

 //The reference type is System.Object and // there is no instance. object x = null; 

Using a variable of a reference type that does not have an instance will result in the exclusion of a null reference.

 string s = null; s = s + "a"; //BOOM. 

Value type variables

Variables of type value have one type, and assigned values ​​must be of this type and not contain others.

 int i = 3; 

With some value type variables (only those of type Nullable<T> ), null can be assigned. This indicates a lack of value.

 int? i = null; 

Using a value type that does not have a value does not throw null reference exceptions - the links are not connected.

 int? i = null if (i < 3) //false 
+3
source share

I think null is not in itself.

+1
source share

null is not a type, it is a value. More specifically, this value, which by definition is the absence of value. In C #, null is converted to any reference type.

Thus, null does not inherit from System.Object, but it is a value convertible to any object that does not inherit from System.ValueType.

0
source share

All Articles