Appendix B Data Types

The following table summarizes the C# data types.

TypeSizeValue
bool2 bytesMust be true or false.
byte1 byte0 to 255 (unsigned byte).
sbyte1 byte–128 to 127 (signed byte).
char2 bytes0 to 65,535 (unsigned character).
short2 bytes–32,768 to 32,767.
ushort2 bytes0 through 65,535 (unsigned short).
int4 bytes–2,147,483,648 to 2,147,483,647.
uint4 bytes0 through 4,294,967,295 (unsigned integer).
long8 bytes–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
ulong8 bytes0 through 18,446,744,073,709,551,615 (unsigned long).
decimal16 bytes0 to +/–79,228,162,514,264,337,593,543,950,335 with no decimal point. 0 to +/–7.9228162514264337593543950335 with 28 significant diits.
float4 bytes–3.4028235E+38 to –1.401298E-45 (negative values). 1.401298E–45 to 3.4028235E+38 (positive values).
double8 bytes–1.79769313486231570E+308 to –4.94065645841246544E–324 (negative values). 4.94065645841246544E–324 through 1.79769313486231570E+308 (positive values).
stringvariesDepending on the platform, approximately 0 to 2 billion Unicode characters.
DateTime8 bytesJanuary 1, 0001 0:0:00 to December 31, 9999 11:59:59 p.m.
object4 bytesPoints to any type of data.
(class)variesClass members have their own ranges.
(structure)variesStructure 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.