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

Aly Khedr
Aly Khedr
470 Points

I don't know what I did wrong. My code should see if the string Language is equal to "C#" and then write what C# rocks!

I sort of wrote everything in the title.

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

if(language == "C#")
{
    Console.Write("C# Rocks!")
}

1 Answer

Steven Parker
Steven Parker
210,933 Points

You're just missing a semicolon.

The line with the Write should end with a semicolon (";").

When something goes wrong, many times you can get some information that will help fix it by hitting the Preview button. This is particularly true when it says your code "could not be compiled." In this case, the Preview showed the error message: "error CS1002: ; expected".

Aly Khedr
Aly Khedr
470 Points

I did what you said and added the semicolon and still nothing

Steven Parker
Steven Parker
210,933 Points

Maybe you put it in the wrong place? Please show the code that you are entering now.

Aly Khedr
Aly Khedr
470 Points

string language = Console.ReadLine();

if(language == "C#"); { Console.Writeline("C# Rocks!"); }

Steven Parker
Steven Parker
210,933 Points

Ahh, you added two semicolons, one in the right place, and another in a wrong place.

There should not be a semicolon between the conditional expression of the if statement and the open brace of the code block.

Aly Khedr
Aly Khedr
470 Points

Wrath of the semicolon. thank you.