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

Sadaf Owais
Sadaf Owais
714 Points

If/Else exercises

I am failing in the IF/Else exercise. If Language = "C#" then print code "C# Rocks!

CodeChallenge.cs
string language = Console.ReadLine();
if {
  language = "C#"
    Console.Write("C# Rocks!")
}

2 Answers

2 issues. Your expression is in the wrong spot. It should be if (expression) {};

Second, a single equals sets a variable. To check, you need double equals (i.e. == ).

So you get:

if( language == "C#") { Console.Write("C# Rocks!"); }

(And don't forget your semi-colons after the Console.Write()! )

Kourosh Raeen
Kourosh Raeen
23,732 Points

Hi Sadaf - After if you need a set of parenthesis. Inside the parenthesis you can check if language is equal to "C#". Remember that to check for equality you need == and also your Console.Wrtite() statement need to end with a semicolon.