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

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,733 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.