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 i get help in this if/else

i need someone to tell me my mistake.

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

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

2 Answers

If you need anything printed, you need to add a print statement. Something like this

System.Console.WriteLine("is not C#");

instead of 
language = "is not C#";

or you can even do this ... 

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

I am just pointing you into the right direction.  You choose.
ali raafat
ali raafat
444 Points

what is the difference

ali raafat
ali raafat
444 Points

its not working in tried both

Hello

the problem is in the else statement. else is executed when the condition in the if statement is not met. Therefore, else is what you want the code to do when if is by passed

string language = Console.ReadLine();

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

try this instead(please note the = insted of ==)

string language = Console.ReadLine();

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

If this answers your question, please mark the question as answered.

ali raafat
ali raafat
444 Points

nothing was printed out its not working