Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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