1. Variables (Definition + Explanation + Examples)
What is a Variable?
A variable is a container that stores data in memory while the program is running.
Think of a variable like a box with a label:
The label = variable name
What you put inside the box = value
The type of box = data type
Example
int age = 25;
string name = "Sandhiya";
Here:
Key Points About Variables
Must have a data type
Must have a name
Can store a value
Value can change
Real-Time Example (Easy to Understand)
Imagine booking a movie ticket website.
Your Age → int variable
Your Name → string variable
Ticket cost → double variable
Is the payment successful? → bool variable
Example
string customerName = "Sandhiya";
int customerAge = 23;
double ticketPrice = 150.50;
bool isPaymentDone = true;
2. DATA TYPES (Definition + Uses + Examples)
What is a Data Type?
A data type tells C# what kind of value a variable can store.
Example
int age = 22;
int tells the computer:
"This variable will store whole numbers."
C# Data Types Fully Explained
A. Primitive (Basic) Data Types
1. int (Integer)
Stores whole numbers (no decimals)
int salary = 30000;
2. double (Decimal numbers)
Stores numbers with decimals
double rating = 4.5;
3. float (Decimal, smaller precision)
Ends with f
float temperature = 36.6f;
4. decimal (Money values — highest accuracy)
Ends with m
decimal productPrice = 999.75m;
Used for payment apps, billing systems, e-commerce
(because money requires accuracy)
5. char (Single character)
Must be single quotes ' '
char grade = 'A';
6. bool (True/False)
Used for conditions
bool isLoginSuccess = false;
7. string (Text)
Stores multiple characters.
string city = "Chennai";
B. Non-Primitive Types
8. Arrays
Stores multiple values of same type
int[] marks = { 80, 90, 95 };
9. List
Dynamic collection (very common in C# & .NET Core)
List<string> names = new List<string>();
names.Add("Sandhiya");
names.Add("Priya");
Real-Time Example: Food Delivery App Data Types
| Information | Example Value | C# Data Type |
|---|
| Customer Name | "Sandhiya" | string |
| Customer Age | 23 | int |
| Order Price | 450.75 | double |
| Order Status | true/false | bool |
| OTP Code | '5' | char |
| List of Items | ["Burger", "Pizza"] | List |
C# Program Example: Variables + Data Types
using System;
class Program
{
static void Main(string[] args)
{
string customerName = "Sandhiya";
int quantity = 2;
double price = 150.50;
bool isDelivered = false;
double total = quantity * price;
Console.WriteLine("Customer: " + customerName);
Console.WriteLine("Quantity: " + quantity);
Console.WriteLine("Total Price: " + total);
Console.WriteLine("Order Delivered: " + isDelivered);
}
}