C# C# Basics (Retired) Perform if / else

Onique Mcfarlane
Onique Mcfarlane
4,708 Points

help with C# if/else

Can't understand whats wrong

CodeChallenge.cs
string language = Console.ReadLine();

if (language == "C#");

{
Console.WriteLine("C# Rocks!");
}

else 

{
Console.WriteLine(language + " is not C#.");
}

1 Answer

andren
andren
28,390 Points

The issue is this line:

if (language == "C#"); // <- The ; does not belong there

You have added a semicolon after the parenthesis, which is incorrect. When you place a semicolon like that it tells C# that the if statement is finished. Even though in reality it has not really done anything yet. This causes the code that should only run if theif statement is true to always run.

You can fix the issue by simply removing the semicolon.