O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.3. Value types

C# value types are close to Java primitives, but there are significant differences. Value types will be your enums (see Chapter 25) and structs (see Chapter 26). Simple types (or primitive types of Java) such as int, byte, and float are special predefined struct types which you can use directly.

While reference types store a reference to an object on the heap, value types directly contain their data. As such, similar to the case of Java's primitives, when you assign one value type to another, a new value is created. Each of the value type variables will store their own copy of the values, and changing the value of one will not affect the value stored in the other. The code below illustrates this:

 1: using System; 2: 3: public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required