O'Reilly logo

C# 3.0 Cookbook, 3rd Edition by Stephen Teilhet, Jay Hilyard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 20. Numbers and Enumerations

20.0. Introduction

Simple types are value types that are a subset of the built-in types in C#, although, in fact, the types are defined as part of the .NET Framework Class Library (.NET FCL). Simple types are made up of several numeric types and a bool type. These numeric types consist of a decimal type (decimal), nine integral types (byte, char, int, long, sbyte, short, uint, ulong, ushort), and two floating-point types (float, double). Table 20-1 lists the simple types and their fully qualified names in the .NET Framework.

Table 20-1. The simple data types

Fully qualified name

Alias

Value range

System.Boolean

bool

true or false

System.Byte

byte

0 to 255

System.SByte

sbyte

-128 to 127

System.Char

char

0 to 65535

System.Decimal

decimal

-79,228,162,514,264,337,593,543,950,335 to 79,228,162,514,264,337,593,543,950,335

System.Double

double

-1.79769313486232e308 to 1.79769313486232e308

System.Single

float

-3.40282347E+38 to 3.40282347E+38

System.Int16

short

-32768 to 32767

System.Uint16

ushort

0 to 65535

System.Int32

int

-2,147,483,648 to 2,147,483,647

System.UInt32

uint

0 to 4,294,967,295

System.Int64

long

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

System.UInt64

ulong

0 to 18,446,744,073,709,551,615

When dealing with floating point data types, precision can be can be more important than the range of the data values. The precision of the floating point data types is listed in Table 20-2.

Table 20-2. Floating point precision

Floating point type

Precision

System.Single (float)

7 digits ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required