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 / else

Code Challenge: If/else

Print “C# Rocks!” if language equals “C#” otherwise print language + “ is not C#.” So if I entered "Cheese" then "Cheese is not C#" would be printed to the screen.

I am getting a bunch of errors(listed below). im not sure what most of them are telling me.

StudentsCode.cs(15,41): error CS1056: Unexpected character “' StudentsCode.cs(15,42): error CS1525: Unexpected symbolis' StudentsCode.cs(15,50): error CS1644: Feature type pattern matching' cannot be used because it is not part of the C# 6.0 language specification StudentsCode.cs(15,51): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line StudentsCode.cs(15,53): error CS1056: Unexpected character”' StudentsCode.cs(15,53): error CS1525: Unexpected symbol `)' Compilation failed: 6 error(s), 0 warnings

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

if(language == "C#")
{
    System.Console.WriteLine("C# Rocks!");
}
else
{
    System.Console.WriteLine(language +  is not C#.);
}

why is "is" highlighted in a string?

2 Answers

Steven Parker
Steven Parker
231,269 Points

:point_right: Your last line has the wrong kind of quotes.

As you could see from the highlighting, your last line has word-processing type quotes instead of programming quotes. Besides the highlighting, you can also tell the difference as the word-processing kind look different on the left and right side. See this example:

    System.Console.WriteLine(language +  is not C#.);  // wrong quotes
    System.Console.WriteLine(language + " is not C#.");  // right quotes

I'm in favor of using copy-paste for strings in the challenges to avoid typo's, but remember to not copy the quotes!

yeah I typed it out and it works perfectly. thank you.

Steven Parker No, typing allows students to remember what they're copying better, and also gives them the chance to change it as they go. If Christopher had copied the code by typing it out that problem would not exist, and any other errors made would give them a chance to learn to correct them as well.

Steven Parker
Steven Parker
231,269 Points

SC3 Rocks, the kind of copy-and-paste I am promoting is limited to the just the strings that are part of the challenges, which do not represent anything to be learned for later use.

And even then, only because passing the challenge requires letter-for-letter accuracy.

Steven is right, also try to copy from the workspace within treehouse instead of somewhere else.