Learn C# Programming
Master C# programming from basics to advanced concepts with our comprehensive tutorial series. Perfect for beginners and experienced developers.
C# if...else Statement
The if...else statement allows you to execute different blocks of code based on conditions.
Basic if Statement
int age = 18;
if (age >= 18)
{
Console.WriteLine("You are an adult");
}
if...else Statement
int score = 85;
if (score >= 90)
{
Console.WriteLine("Grade: A");
}
else
{
Console.WriteLine("Grade: B or lower");
}
if...else if...else Statement
int score = 85;
if (score >= 90)
{
Console.WriteLine("Grade: A");
}
else if (score >= 80)
{
Console.WriteLine("Grade: B");
}
else if (score >= 70)
{
Console.WriteLine("Grade: C");
}
else if (score >= 60)
{
Console.WriteLine("Grade: D");
}
else
{
Console.WriteLine("Grade: F");
}
Nested if Statements
int age = 25;
bool hasLicense = true;
if (age >= 18)
{
if (hasLicense)
{
Console.WriteLine("You can drive");
}
else
{
Console.WriteLine("You need a license to drive");
}
}
else
{
Console.WriteLine("You are too young to drive");
}
Logical Operators in Conditions
int age = 25;
bool hasJob = true;
double income = 50000;
// AND operator
if (age >= 18 && hasJob)
{
Console.WriteLine("Eligible for loan");
}
// OR operator
if (age >= 65 || income < 20000)
{
Console.WriteLine("Eligible for discount");
}
// NOT operator
if (!hasJob)
{
Console.WriteLine("Unemployed");
}
💡 Best Practices
- Always use braces {} even for single statements
- Keep conditions simple and readable
- Use logical operators to combine conditions
- Consider using switch for multiple discrete values
Frequently Asked Questions
Master C# Programming with Our Comprehensive Tutorial
Our C# programming tutorial is designed to take you from a complete beginner to an advanced developer. Whether you're looking to build web applications, desktop software, or mobile apps, C# provides the foundation you need for modern software development.
Start with the basics like variables, data types, and control structures, then progress to advanced topics including object-oriented programming, LINQ, async programming, and more. Each lesson includes practical examples and exercises to reinforce your learning.
Join thousands of developers who have learned C# programming through our step-by-step tutorials. Begin your journey today and unlock the power of .NET development.