Admin Name
Dashboard
Categorey
Sub Categorey
Artilces
Users
Settings
Logout
Welcome to the Admin Panel
Create Post
Select Categorey
- Select -
coding
Select Sub Categorey
Title Name :
Defination :
Conditional statements in C# are used to perform different actions based on different conditions. These are essential to control the flow of a program.
Code :
using System; namespace ConditionalDemo { class Program { static void Main(string[] args) { int marks = 85; if (marks >= 90) { Console.WriteLine("Grade: A+"); } else if (marks >= 75) { Console.WriteLine("Grade: A"); } else if (marks >= 60) { Console.WriteLine("Grade: B"); } else { Console.WriteLine("Grade: C"); } // Switch Case Example int day = 3; switch (day) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; default: Console.WriteLine("Another day"); break; } } } }
Code Part 2 :
Upload Image 1
Upload Image 2
Summary
The program starts by declaring an integer variable marks with a value of 85. It enters the if statement: First, it checks marks >= 90 ? False, so it moves to the next condition. Then, marks >= 75 ? True, so it prints Grade: A and skips the rest of the conditions. Next, the program defines a day variable with value 3. In the switch statement: Case 3 matches, so it prints Wednesday. These conditional structures are vital to make decisions in programming.
YouTube Link
Seo Title
Meta Keywords
Meta Description
Introduction to C#
Edit
Variables and Data Types in C#
Edit
Operators in C#
Edit
Control Statements in C# – if, else, switch, and loops Explained
Edit
Loops in C# – for, while, do while, and foreach
Edit
Jump Statements in C# – break, continue, return Explained with Examples
Edit
Conditional Statements in C# if, else if, else, switch Explained with Examples
Edit
Loops in C# – For, While, and Do While with Examples
Edit
Hrjejd
Edit