5.14 Simple Types

The table in Appendix B lists C#’s 13 simple types. Like its predecessor languages C and C++, C# requires all variables to have a type.

In C and C++, you frequently have to write separate versions of apps to support different computer platforms, because the simple types are not guaranteed to be identical from computer to computer. For example, an int value on one machine might be represented by 16 bits (2 bytes) of storage, while an int value on another machine might be represented by 32 bits (4 bytes) of storage. In C#, int values are always 32 bits (4 bytes). In fact, all C# numeric types have fixed sizes, as is shown in Appendix B.

Each type in Appendix B is listed with its size in bits (there are eight bits to a byte) and its range of values. Because the designers of C# want it to be maximally portable, they use internationally recognized standards for both character formats (Unicode; http://unicode.org) and floating-point numbers (IEEE 754; http://grouper.ieee.org/groups/754/).

Recall that variables of simple types declared outside of a method as instance variables of a class are automatically assigned default values unless explicitly initialized. Instance variables of types char, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and decimal are all given the value 0 by default. Instance variables of type bool are given the value false by default. Similarly, reference-type instance variables are initialized by default to the value null.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset