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

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.