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

ali raafat
ali raafat
444 Points

can someone help me with if/else

i got " nothing was printed out." can you tell me my mistake

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

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

       language = "is not C#";
}

1 Answer

In the else clause you assigned the value of "is not C#" but you didn't print it to the screen.

language = "is not C#";

You need to add System.Console.WriteLine(language + " is not C#");

A little beyond the challenge it would be best to assign a variable with "C# rocks" or lanague + " is not C#" and then print it after your if statement. That way your not duplicating the System.Console.WriteLine statement.

What's amazing is this can eventually be refactors to a much simpler statement like:

System.Console.WriteLine(language == "C#" ? "C# Rocks" : $"{language} is not C#");