Simple Types

The table in Appendix L, Simple Types, lists the thirteen simple types in C#. Like its predecessor languages C and C++, C# requires all variables to have a type. For this reason, C# is referred to as a strongly typed language.

In C and C++, programmers frequently have to write separate versions of applications 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 memory, while an int value on another machine might be represented by 32 bits (4 bytes) of memory. In C#, int values are always 32 bits (4 bytes). In fact, all C# numeric types have fixed sizes, as is shown in Appendix L, Simple Types.

Each type in Appendix L 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; for more information, visit www.unicode.org) and floating-point numbers (IEEE 754; for more information, visit grouper.ieee.org/groups/754/).

Recall from Section 4.5 that variables of simple types declared outside of a method as fields 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.

(Optional) Software Engineering Case Study Identifying Class Attributes in the ATM System

Категории