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

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
231,248 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
231,248 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
231,248 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.