C# C# Basics (Retired) Perform if / else

IF/ELSE

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

}

Someone please explain me where is the mistake?

thx

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

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


}

2 Answers

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! The problem lies in the string that you're printing in the else statement. You seem to understand that you need a space, but seem unsure how to do it. Right now, if I were to send in "Java", your code would print out:

Javais not C#.

But we would want it to print out:

Java is not C#.

Note the space between the value of language and the rest of the string. To do this, we can simply add an extra space in our string literal.

Console.WriteLine(language + " is not C#.");

This would print out the language we typed in with the appropriate spacing. Remember that when you print the value of a variable, no spacing is implied. If you want spacing, you have to explicitly put it somewhere.

Hope this helps! :sparkles:

Thanks a prompt reply! All clear