Information Technology Reference
In-Depth Information
Remember that for a reference type, the data of an instance is always stored in the heap.
Since both members are part of the object's data, they are both stored in the heap, regardless
of whether they are value or reference types. Figure 3-10 illustrates the case of type MyType .
Even though member A is a value type, it is stored in the heap because it is part of the
data of the instance of MyType .
￿
￿Member B is a reference type, and therefore its data portion will always be stored in the
heap, as shown by the small box marked “Data.” What's different is that its reference is
also stored in the heap, inside the data portion of the enclosing MyType object.
Figure 3-10. Storage of data as part of a reference type
Note For any object of a reference type, all its data members are stored in the heap, regardless of
whether they are of value type or reference type.
Categorizing the C# Types
Table 3-3 shows all the types available in C# and what kinds of types they are—value types or
reference types. I will cover each type in this text.
Table 3-3. Value Types and Reference Types in C#
Value Types
Reference Types
sbyte
short
int
long
bool
byte
ushort
uint
ulong
float
double
char
decimal
object
string
Predefined Types
struct
enum
class
interface
delegate
array
User-Defined Types
Search WWH ::




Custom Search