EDIT I had to start with this example in 1st place:
Think about transfers. Each enumerated number that we write automatically extends Enum , which is a class. Therefore, the types of values that we write extend the class written by the .NET command, which is a reference type.
You can divide the world of types in two ways:
- whether they contain
null or not - whether they are value types or not
All combinations are possible in theory. If I'm not mistaken, at least in C #, a combination of reference types that cannot be null gives an empty set. There is no example for this combination.
In principle, all other 3 combinations are possible:
- types that can be empty and are value types
- types that cannot be empty and are value types
- types that can be null and are reference types
The nature of being either a value type or a reference type has nothing to do with null (at least in how languages should be designed and used, and not based on actual technical data below).
Value types are types that cause assignment between variables, parameters, and fields to fully clone an instance. Link types are types that do not.
This has nothing to do with null or with the type of memory that is occupied by the instances (whether it be a stack, a heap, or something else).
source share