Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,424 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!");
}