Appendix B Data Types
The following table summarizes the C# data types.
Type | Size | Value |
bool | 2 bytes | Must be true or false . |
byte | 1 byte | 0 to 255 (unsigned byte). |
sbyte | 1 byte | –128 to 127 (signed byte). |
char | 2 bytes | 0 to 65,535 (unsigned character). |
short | 2 bytes | –32,768 to 32,767. |
ushort | 2 bytes | 0 through 65,535 (unsigned short ). |
int | 4 bytes | –2,147,483,648 to 2,147,483,647. |
uint | 4 bytes | 0 through 4,294,967,295 (unsigned integer). |
long | 8 bytes | –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. |
ulong | 8 bytes | 0 through 18,446,744,073,709,551,615 (unsigned long). |
decimal | 16 bytes | 0 to +/–79,228,162,514,264,337,593,543,950,335 with no decimal point. 0 to +/–7.9228162514264337593543950335 with 28 significant diits. |
float | 4 bytes | –3.4028235E+38 to –1.401298E-45 (negative values). 1.401298E–45 to 3.4028235E+38 (positive values). |
double | 8 bytes | –1.79769313486231570E+308 to –4.94065645841246544E–324 (negative values). 4.94065645841246544E–324 through 1.79769313486231570E+308 (positive values). |
string | varies | Depending on the platform, approximately 0 to 2 billion Unicode characters. |
DateTime | 8 bytes | January 1, 0001 0:0:00 to December 31, 9999 11:59:59 p.m. |
object | 4 bytes | Points to any type of data. |
(class) | varies | Class members have their own ranges. |
(structure) | varies | Structure members have their own ranges. |
Casting and Converting Values
You can use a cast to convert a value into a compatible data type. For example, the following code declares and initializes a long
variable. It then uses a ...
Get C# 5.0 Programmer's Reference 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.