Data Types in C#: Double, Integer, Float, Char
⚡ Smart Summary
Data types in C# define the kind of values a variable can hold, ranging from integers and floating-point numbers to Boolean and string values, and they determine how much memory each variable reserves during program execution.

What are Data Types in C#?
The C# language comes with a set of Basic data types. These data types are used to build values which are used within an application. Let’s explore the basic data types available in C#. For each example, we will modify just the main function in our Program.cs file.
1) Integer
An Integer data types are used to work with numbers. In this case, the numbers are whole numbers like 10, 20 or 30. In C#, the datatype is denoted by the Int32 keyword. Below is an example of how this datatype can be used. In our example, we will define an Int32 variable called num. We will then assign an Integer value to the variable and then display it accordingly.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class Program { static void Main(string[] args) { Int32 num=30; Console.Write(num); Console.ReadKey(); } } }
Code Explanation:-
- The Int32 data type is specified to declare an Integer variable called num. The variable is then assigned a value of 30.
- Finally the console.write function is used to display the number to the console.
If the above code is entered properly and the program is executed successfully, following output will be displayed.
Output:
From the output, you can clearly see that the Integer variable called num was displayed in the console
2) Double
A double data type is used to work with decimals. In this case, the numbers are whole numbers like 10.11, 20.22 or 30.33. In C#, the datatype is denoted by the keyword “Double“. Below is an example of this datatype.
In our example, we will define a double variable called num. We will then assign a Double value to the variable and then display it accordingly.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class Program { static void Main(string[] args) { double num=30.33; Console.Write(num); Console.ReadKey(); } } }
Code Explanation:-
- The double data type is specified to declare a double type variable called num. The variable is then assigned a value of 30.33.
- Finally the console.write function is used to display the number to the console.
If the above code is entered properly and the program is executed successfully, following output will be displayed.
Output:
From the output, you can clearly see that the double variable called num was displayed in the console
3) Boolean
A boolean data type is used to work with Boolean values of true and false. In C#, the datatype is denoted by the Boolean keyword. Below is an example of this datatype can be used.
In our example, we will define a Boolean variable called ‘status.’ We will then assign a boolean value to the variable and then display it accordingly.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class Program { static void Main(string[] args) { Boolean status=true; Console.Write(status); Console.ReadKey(); } } }
Code Explanation:-
- The boolean data type is specified to declare a Boolean variable called ‘status.’ The variable is then assigned a value of true/false.
- Finally the console.write function is used to display the Boolean value to the console.
If the above code is entered properly and the program is executed successfully, the output will be displayed.
Output:
From the output, you can clearly see that the Boolean variable which equals true was displayed in the console
4) String
A String data type is used to work with String values. In C#, the datatype is denoted by the keyword ‘String’. Below is an example of this datatype.
In our example, we will define a String variable called ‘message.’ We will then assign a String value to the variable and then display it accordingly.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DemoApplication { class program { static void Main(string[] args) { String message="Hello"; Console.Write(message); Console.ReadKey(); } } }
Code Explanation:-
- The String data type is specified to declare a string variable called message. The variable is then assigned a value of “Hello”.
- Finally, the console.write function is used to display the string value to the console.
If the above code is entered properly and the program is executed successfully, the output will be displayed.
Output:
From the output, you can clearly see that the String variable called message was displayed in the console
Complete List of C# Data Types
The four examples above cover the most common types, but C# provides a full set of built-in value data types. Each type reserves a fixed amount of memory and accepts a specific range of values, so choosing the smallest type that safely fits your data keeps a program efficient.
| Data Type | Size | Range / Description |
|---|---|---|
| byte | 1 byte | 0 to 255 |
| short | 2 bytes | -32,768 to 32,767 |
| int (Int32) | 4 bytes | -2,147,483,648 to 2,147,483,647 |
| long | 8 bytes | Very large whole numbers (±9.2 quintillion) |
| float | 4 bytes | Decimals with roughly 6–7 digit precision |
| double | 8 bytes | Decimals with roughly 15–16 digit precision |
| decimal | 16 bytes | High-precision decimals (28–29 digits) for money |
| char | 2 bytes | A single Unicode character |
| bool | 1 byte | true or false |
Alongside these value types, the string type is the most widely used reference type and stores a sequence of characters of any length. Selecting an appropriate type prevents overflow errors and unnecessary memory use.
Value Types vs Reference Types in C#
Every C# data type falls into one of two groups: value types and reference types. This distinction controls how C# stores the data and how a variable behaves when you copy it or pass it to a method.
- Value types: These store the actual data directly, usually on the stack. int, double, bool, char, enum, and struct are value types. Assigning one variable to another copies the value, so the two variables remain independent.
- Reference types: These store a reference (a memory address) that points to data on the heap. string, object, arrays, and class instances are reference types. Copying a reference variable copies only the address, so both variables share the same object.
A value type variable can never be null because it always holds a value, whereas an uninitialized reference type defaults to null. Understanding this difference helps you predict how changes to data flow through a program.
Type Conversion in C#
C# frequently needs to move a value from one data type to another, such as turning user input, which is always text, into a number. This process is called type conversion, and it happens in three main ways.
- Implicit conversion: The compiler converts automatically when there is no risk of data loss, such as assigning an int to a double. No special syntax is required.
- Explicit conversion (casting): You place the target type in parentheses, for example (int)myDouble. Casting can lose data — converting a double to an int drops the decimal part — so you accept the risk deliberately.
- Helper methods: The Convert class (Convert.ToInt32) and each type’s Parse method (int.Parse) turn strings into numbers, while ToString turns values back into readable text.
Choosing the correct conversion keeps data accurate and prevents runtime errors when the types on each side of an assignment do not match.








