Types
C# is a strongly typed language. That means that every object you create or use in a C# program must have a specific type. In other words, you must declare the object to be an integer or a string or a Dog
or a Button
. Essentially, the type indicates the characteristics of the object and what it can do.
Types come in two flavors: those that are built into the language (intrinsic types) and those you create yourself (classes and interfaces, discussed in Chapters Chapter 7 and Chapter 13). C# offers a number of intrinsic types, shown in Table 3-1.
Table 3-1. The intrinsic types built into C#
C# type | Size (in bytes) | .NET type | Description |
---|---|---|---|
| 1 |
| Unsigned (values between 0 and 255). |
| 2 |
| Unicode characters (a modern way of storing most characters, including international language characters). |
| 1 |
| True or false. |
| 1 |
| Signed (values between –128 and 127). |
| 2 |
| Signed (short) (values between –32,768 and 32,767). |
| 2 |
| Unsigned (short) (values between 0 and 65,535). |
| 4 |
| Signed integer values between –2,147,483,648 and 2,147,483,647. |
| 4 |
| Unsigned integer values between 0 and 4,294,967,295. |
| 4 |
| Floating-point number. Holds the values from approximately +/-1.5 x 10-45 to approximately +/-3.4 x 1038 with seven significant figures. |
| 8 |
| Double-precision floating-point. Holds the values from approximately +/-5.0 x 10-324 to approximately +/-1.8 x 10308 with 15 to 16 significant figures. |
| 12 |
| Fixed-precision up to 28 digits and the position ... |
Get Learning C# 3.0 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.