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

Kanwaldeep Sekhon
PLUS
Kanwaldeep Sekhon
Courses Plus Student 1,298 Points

Pre-processor errors on "if" code

I've written the code for the challenge exactly as the instructor had taught it, but I keep getting a compiler error and not sure why. It says the first character should be a non-white space but that doesn't add up to what we went over in the lecture. I've tried the code several different ways and still can't get anywhere with it. Please help! :-(

CodeChallenge.cs
bool C# = true;
{string language = Console.ReadLine();
    if (language == "C#")
        {
             C# = true;
        }
}
Console.WriteLine("C# Rocks!");

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First, it was not necessary to create a new variable for this challenge. Also, C# is not a valid variable name. The Console.WriteLine(); should be inside the if statement. Take a look:

string language = Console.ReadLine();
if (language == "C#") {
    Console.WriteLine("C# Rocks!");
}

The variable language is set up by the challenge. If the value of the variable is equal to "C#" then "C# Rocks!" will be printed out to the console.

Hope this helps! :sparkles:

Kanwaldeep Sekhon
Kanwaldeep Sekhon
Courses Plus Student 1,298 Points

Ah! Ok, thank you Jennifer. I was putting more thought into it and over-complicating the code.