Data Types in C#

In the last lesson, you saw how to set up the C# environment and how to install your first C# program. In this lesson, you will study the concept of data types and variables in C#. A variable is basically placeholder that is used to store data of a particular data type. A variable points to the memory location where the actual data is stored.

C# datatypes can be broadly categorized into four types:

  1. Numeric
  2. Boolean
  3. String
  4. Char

Numeric Data Type

Numeric data types in C# are used to store numeric data. The following table shows commonly used numeric data types supported by C#:

Data TypeDefault ValueSize
int04 byte
signed int04 byte
unsigned int04 byte
long08 byte
signed long08 byte
unsigned long08 byte
float0.0F4 byte
double0.0D8 byte
decimal0.0M16 byte

Let’s now see a very simple example that uses some of these numeric operators:

Boolean Data

The boolean data type is used to store boolean data. In C#, the word “bool” is used to store boolean data. A “bool” type variable can have two values: True or False. The following example will further clear the use of boolean variable.