7.3. The C# Value Type

The C# value type stores data. The assignment to a variable of a value type creates a copy of the assigned value. Following are some of the common features of C# value types:

  • Unlike the Java primitive, all boxed C# value types are derived from the System.Object class.

  • A value type cannot contain the null value.

  • Each value type has a default constructor that initializes the default value of the type.

  • A value type cannot inherit from another value type.

  • The memory allocated for value types is usually allocated on the stack; this contrasts with reference types, for which the memory is allocated on the heap.

  • You can create new C# value types. In Java, the primitives are a fixed set.

C# defines two key-value types: struct types and ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.