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 trial

C# C# Basics (Retired) Perform if

Idan shami
Idan shami
13,251 Points

i need help in the challenge

my problem is that this keeps print me c# rocks whatever i write in the console...

CodeChallenge.cs
string language = Console.ReadLine();
if (language.Equals("c#")); 
{ 
    Console.WriteLine("c# rocks!");
}

2 Answers

Steven Parker
Steven Parker
229,788 Points

There's a stray semicolon after the conditional expression of the "if" statement. That ends the statement and causes the following code block to run all the time instead of only when the condition is true.

Also, C# is case-sensitive, and the challenges can be very picky about input and output strings. So be sure to spell "C#" with a capital "C".

You have two issues in your code: first, you have placed a semicolon(;) after your if statement. This is not correct. That is what is causing your current error. Second, you would get another error even if you remove the semicolon because you have used the lower case letter 'c' instead of capital 'C'. The second error is not a true error in the language C#, but it would still cause your code to not pass the strict requirements of the tests used to evaluate your code for this challenge.

string language = Console.ReadLine();

if (language.Equals("C#")
{
    Console.WriteLine("C# rocks!");
}