C# Break and Continue
C# Break and Continue In C#, break and continue are loop control statements used to change the normal flow of loops (for, while, do-while, foreach, and switch). break Statement The break statement is used...
C# Break and Continue In C#, break and continue are loop control statements used to change the normal flow of loops (for, while, do-while, foreach, and switch). break Statement The break statement is used...
C# For Loop The for loop in C# is used to repeat a block of code a specific number of times. It is best when you know in advance how many iterations are required....
C# While Loop The while loop in C# is used to repeat a block of code as long as a condition is true. It is best used when you don’t know in advance how...
C# Switch Statement The switch statement in C# is used to execute one block of code from many choices. It is a clean alternative to long if…else if chains when comparing a single value....
C# If … Else The if…else statement in C# is used to make decisions. It allows your program to execute different code blocks based on conditions. Basic if Statement
|
1 2 3 4 5 6 |
int age = 20; if (age >= 18) { Console.WriteLine("Eligible to vote"); } |
✔ Executes only...
C# Booleans In C#, booleans are used to store true or false values. They are mainly used in conditions, comparisons, and decision-making statements. Boolean Data Type The boolean data type in C# is called...
C# Strings In C#, a string is used to store text. Strings are objects of the String class and are immutable, meaning once created, they cannot be changed. Declaring Strings
|
1 2 |
string name = "Vipul"; string city = "Surat"; |
String Output
|
1 2 |
string message = "Hello C#"; Console.WriteLine(message); |
...
C# Math C# provides the Math class (in the System namespace) to perform common mathematical operations like rounding, power, square root, min/max, and trigonometry. Basic Math Operations
|
1 2 3 4 5 6 |
int a = 10; int b = 3;Console.WriteLine(a + b); // Addition Console.WriteLine(a - b); // Subtraction Console.WriteLine(a * b); // Multiplication Console.WriteLine(a / b); // Division Console.WriteLine(a % b); // Modulus |
Math Class (System.Math) ✔ Common...
C# Operators Operators in C# are symbols used to perform operations on variables and values, such as arithmetic calculations, comparisons, and logical decisions. Types of Operators in C# Arithmetic Operators Assignment Operators Comparison (Relational)...
C# User Input In C#, user input is commonly taken from the keyboard using the Console.ReadLine() method. 🔹 Basic User Input
|
1 2 3 4 |
Console.Write("Enter your name: "); string name = Console.ReadLine(); Console.WriteLine($"Hello, {name}"); |
🔹 Input with Numbers (Type Casting Required) Console.ReadLine() always returns a...