C# PROGRAMMING FUNDAMENTALS (BASIC NOTES)
1. INPUT AND OUTPUT
Output in C#
Output means displaying data on the screen.
Function used:
[Link]()
Example:
using System;
class Program
{
static void Main()
{
[Link]("Hello World");
}
}
Output:
Hello World
Easy Concept:
[Link]() = Print on screen
Input in C#
Input means taking data from the user.
Function used:
[Link]()
Example:
using System;
class Program
{
static void Main()
{
[Link]("Enter your name:");
string name = [Link]();
[Link]("Hello " + name);
}
}
Output Example:
Enter your name:
Ali
Hello Ali
Easy Concept:
[Link]() = Read input from user
2. VARIABLES
What is a Variable?
A variable is a container used to store data.
Syntax:
dataType variableName = value;
Example:
int age = 20;
string name = "Ali";
Explanation:
int → stores numbers
string → stores text
age → variable name
20 → value
Example Program:
using System;
class Program
{
static void Main()
{
int age = 20;
string name = "Ali";
[Link](name);
[Link](age);
}
}
Output:
Ali
20
Easy Concept:
Variable = Box to store data
3. DATA TYPES
What are Data Types?
Data types define the type of data a variable can store.
Common Data Types in C#
1. int (Integer)
Stores whole numbers.
int age = 25;
2. float
Stores decimal numbers.
float price = 10.5f;
3. double
Stores large decimal numbers.
double pi = 3.14159;
4. char
Stores a single character.
char grade = 'A';
5. string
Stores text.
string name = "Ali";
6. bool
Stores true or false.
bool isStudent = true;
Easy Table:
Data Type Stores
int Whole numbers
float Decimal numbers
double Large decimals
char Single character
string Text
bool True/False
Example Program:
using System;
class Program
{
static void Main()
{
int age = 20;
float height = 5.6f;
char grade = 'A';
string name = "Ali";
bool isPass = true;
[Link](name);
[Link](age);
[Link](height);
[Link](grade);
[Link](isPass);
}
}
4. OPERATORS
What are Operators?
Operators are symbols used to perform operations on variables.
1. Arithmetic Operators
Used for mathematical calculations.
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (remainder)
Example:
using System;
class Program
{
static void Main()
{
int a = 10;
int b = 5;
[Link](a + b);
[Link](a - b);
[Link](a * b);
[Link](a / b);
[Link](a % b);
}
}
Output:
15
5
50
2
0
2. Relational Operators
Used to compare values.
Operator Meaning
== Equal to
!= Not equal
> Greater than
< Less than
>= Greater or equal
<= Less or equal
Example:
using System;
class Program
{
static void Main()
{
int a = 10;
int b = 5;
[Link](a > b);
[Link](a < b);
[Link](a == b);
}
}
Output:
True
False
False
3. Logical Operators
Used to combine conditions.
Operator Meaning
&& AND
! NOT
Example:
using System;
class Program
{
static void Main()
{
int age = 20;
[Link](age > 18 && age < 25);
}
}
Output:
True