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

Aly Khedr
Aly Khedr
470 Points

UnKnown errors

I asked for help on my older version of this code just a minute ago, but I thought I figured out the problems. Know I'm not sure what the issue is.

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

if(language == "C#");
{
    Console.Write("C# Rocks!");
}
else();
{
    Console.Write("The Cake is a Lie");
}

3 Answers

Antonio De Rose
Antonio De Rose
20,885 Points
you've been not asked to do an else, hence you have to take the else completely out.
in if and else conditions, you should not end with a semicolon
string language = Console.ReadLine();

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

I tried that before I did the Else and it says it typed Bugus and it still printed C# rocks!

Ezequiel Hurt
Ezequiel Hurt
8,061 Points

Hi Aly Khedr, 1) You're only asked to write the IF clause, not an IF ELSE. 2) The Else clause only needs the curly brackets, because it doesn't have any condition, the condition is on the if. It's means that the ELSE clause will be executed only if the IF evaluates to FALSE.

To write an else, the code will be like this

string language = Console.ReadLine();

if(language == "C#")
{
    Console.Write("C# Rocks!");
}
else
{
    Console.Write("This languaje is not C#");
}
Antonio De Rose
Antonio De Rose
20,885 Points

try this

string language = Console.ReadLine();

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