Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOnique Mcfarlane
4,708 Pointshelp with C# if/else
Can't understand whats wrong
string language = Console.ReadLine();
if (language == "C#");
{
Console.WriteLine("C# Rocks!");
}
else
{
Console.WriteLine(language + " is not C#.");
}
1 Answer
andren
28,558 PointsThe 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.