In my previous post Basic Concepts – Part 2, I went over three common types of variables: Integer, String, and Double. In this post, I intend to go over all of the intrinsic data types available to you in C#. Many of these translate to Java, C++, and even other languages like Visual Basic as well.

Let me begin by saying it’s often possible to convert, or cast, variables into other types. For example, it’s easy to cast 27 into a String, which would make it “27”. This doesn’t always work – for example, you can’t convert “Bob” into an Integer – but there is an inherent flexibility with many of the intrinsic data types I’m about to discuss.

BooleanTrue or False, 0 or 1, On or Off.

Range: There are only two possible values for this type of variable.

Example: computerIsOn = False (the computer can only be On or Off, nothing else)

Also Known As: bool


Byte
– 0 to 255.

Range: Including the zero, there are 256 possible values for this variable.

Example: red = 255; green = 0; blue = 0. This would define the color red in an RGB Mapping Space.


Char
– 0 to 65535.

Range: Including the zero, there are 65536 possible values for this variable.

Example: batmanSymbol = 32767. This would define the character representing a Batman Symbol as entry # 32767.


Decimal
– -7.9 x 1028 to 7.9 x 1028) / (100 to 28).

Range: 128 bits

Example: moneySpentOnInsurance = 12768.35m; benefitReceivedFromInsurance = 32.49m. The “m” forces the literal numeric value to be read as a “decimal” and not a “double” (see below).


Double
– ±5.0 × 10−324 to ±1.7 × 10308.

Range: 64 bits

Example: piTimesTenThousand = 31415.92653589793238462


Float
– ±1.5 × 10−45 to ±3.4 × 1038.

Range: 32 bits

Example: avgTempInWisconsin = 14.2834F (the “F” forces the literal numeric value to be read as a “float” and not a “double”)


Integer
– -2,147,483,648 to 2,147,483,647.

Range: 32 bits (signed)

Example: loftFloor = 1; groundFloor = 0; basementGarage = -1. (Signed integers can be positive or negative, butcannot have fractions or decimals – whole numbers only!)

Also Known As: int


Long
– -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Range: 64 bits (signed)

Example: feetToDestination = -1929382 (can be positive or negative, but must be a whole number)


Sbyte
– -128 to 127.

Range: Including the -128, there are 256 possible values for this variable.

Example: vehicleSpeed = -15. The car is going in reverse at 15 MPH.

netWorth = 10283.94. Doubles can be used to represent large financial amounts.


Short –
-32,768 to 32,767.

Range: 16 bits (signed)

Example: verticalAscentVelocity = -12922 (can be positive or negative, but must be a whole number)


UInteger
– 0 to 4,294,967,295.

Range: 32 bits (unsigned)

Example: peopleInTheOffice = 3 (Unsigned integers are positive whole numbers only)


ULong
– 0 to 18,446,744,073,709,551,615.

Range: 64 bits (unsigned)

Example: nationalDebt = 17971213099640 (Unsigned longs are positive whole numbers only)


UShort
– 0 to 65,535.

Range: 16 bits (unsigned)

Example: lockCombination = 12345 (positive whole numbers only)

 

In Closing

Note that there are various other object types – there’s even an Object object type – however, the ones I listed above are the intrinsic types that all others derive from. For example, in several programming languages, “String” is actually just a collection of “char” entities. In a future post, I will talk about abstraction, inheritance, polymorphism, and a bunch of other neat tricks you can perform with objects.

Share

Comments are closed.

Post Navigation