3.1. Integer Data Types

An integer data type is any numeric value expressed as a whole number. Integer values cannot have a fractional component associated with them. If you try to assign a fractional value to an integer variable, C# truncates the value. For example, if val is an integer data type, the statement

val = 6.9999;

assigns the value of 6 to val. This means that integer operations do not round values. If an integer data type has a fractional value, C# simply throws away the fractional component.

Table 3-1 lists the various integer data types that you can use in your programs.

Table 3-1. Table 3-1
Type SpecifierBitsRangeData Suffix
byte80 through 255 
sbyte8−128 through 127 
short16−32,768 through 32,767 
ushort160 through 65,535 
int32−2,147,483,648 through 2,147,483,647 
uint320 through 4,294,967,295U, u
long64−9,223,372,036,854,775,808 through 9,223,372,036,854,775,807L, l
ulong640 through 18,446,744,073,709,551,615UL, ul

3.1.1. Range of Integer Data Types

Each of the integer data types has a range of values that it can accommodate. Consider the byte data type, which uses eight bits. A binary digit, or bit, is the smallest unit of computer storage and may assume the value of on (1) or off (0). This means that the most basic unit of information in a computer — the bit — only has two possible states: on and off. Because there are only two possible states, information is stored in a computer in a binary, or base-two, format. While you and I perform mathematic operations using ...

Get Beginning 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.