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

My if else statement isn't working on C#. Can someone see the issue for this to compile?

string language = Console.ReadLine();

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

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

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

2 Answers

Erik McClintock
Erik McClintock
45,783 Points

Michael,

The challenge is being picky, and is looking for your string to match EXACTLY. Your code is correct, save for the fact that you have two space characters in the string " is not C#."

// You have:
" is  not C#."

// You need:
" is not C#."

Remove the extra space character between the words "is" and "not", and your code passes just fine!

Erik

Oh man. That was confusing! I kept looking at them both and I was beating myself up!

Thanks.

Emily Kolar
Emily Kolar
2,787 Points

Is it at least returning one of your writeline calls? The one under 'else' should at least be coming back.

If the 'else' writeline isn't getting printed, you could try just using Console.WriteLine() without the System namespace, if you're already "using System" at the top of your file... This might be nonsensical, but it really should be writing that 'else' string at the very least.

If that extra space that Erik pointed out was the problem, please let us know! I'm very interested.

Hi there Emily!

The issue did lie between the space problem. I was very lost for a brief moment! I thought I had this in my grasp.. I suppose TTH does a great job in teaching us to code and pay attention :) .