Table of contents >> Introduction > Variable types
High importance article

When you declare variables in your programs, you must indicate to the compiler the type and the name of the variables. There are many variable types and derivations of them. A type defines the amount of data a variable can store, and the set of operations the program can perform on those data.

C# accepts the following base types, also known as primitive types, with the exception of string, which is a derived type:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
   TYPE       ALIAS FOR        ALLOWED VALUES
================================================================================================
integer numbers variables
   int       System.Int32     Integer between −2147483648 and 2147483647
   byte      System.Byte      Integer between 0 and 255
 
floating point numbers variables
   float     System.Single    7 digits (32 bit)
   double    System.Double    15-16 digits (64 bit)
   decimal   System.Decimal   28-29 significant digits (128 bit)
 
text variables
   string    System.String    A sequence of characters
   char      System.Char      Single Unicode character, stored as an integer between 0 and 65535
 
boolean variables
   bool      System.Boolean   Boolean value, true or false
Additional Information

There are a lot of other types extending on these variables, that are not used as much, or they are used in special cases. While it is unlikely you will be using them any time soon, you should take a look over them to familiarize yourself with their keyword names:

1
2
3
4
5
6
7
8
   TYPE       ALIAS FOR        ALLOWED VALUES
==========================================================================================
   short     System.Int16     Integer between −32768 and 32767
   ushort    System.UInt16    Integer between 0 and 65535
   uint      System.UInt32    Integer between 0 and 4294967295
   long      System.Int64     Integer between −9223372036854775808 and 9223372036854775807
   ulong     System.UInt64    Integer between 0 and 18446744073709551615
   sbyte     System.SByte     Integer between −128 and 127

The u in some keywords stands for unsigned, meaning that the variable uses the sign bit to further store relevant digits, in which case it can store only positive values or 0, but in a greater range. The s in sbyte means signed byte, and, as we will later learn, a byte variable does not have a sign bit; in this case, sbyte is a byte variable that uses a sign bit. This will be further explained in a future lesson.

In the next lesson we will learn how we can give values to our variables.

The concepts explained in this lesson are also shown visually as part of the following video: