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 trialNeil Gordon
8,823 Pointsquick question on my if statement
I've attached my code
bool language = true;
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else {
System.Conole.WriteLine( + "is not C#");
}
4 Answers
Steven Parker
231,269 PointsThe real answer to the original issue was that this piece of code:
bool language = true;
string language = Console.ReadLine();
...was declaring the same variable twice, and as two different types. A variable cannot be declared twice in the same scope.
Once that is fixed, you have an additional issue with this line:
System.Conole.WriteLine( + "is not C#");
It looks like you forgot to put your variable before the + sign. Plus you might want to add a space at the beginning of the string being added on.
Neil Gordon
8,823 PointsFigured it out , I read the question wrong see the answer below
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else {
System.Console.WriteLine(language + " is not C#");
}
Alan Mattanó
Courses Plus Student 12,188 PointsSystem.Conole.WriteLine( + "is not C#");
If you add "+" you are making a concatenation, so you need two parameters. One on left and one on right. Be sure to put a space between words when you are concatenating strings (between " and is. [ "is..." starts with a space "_is.."] ).
System.Conole.WriteLine( language + " is not C#");
Steven Parker
231,269 PointsOdd, this question shows up as having "0 Answers" in the forum index, when it actually has 3.
I'm adding this one to see if it will fix the index.
Followup: No, it didn't.
Alan Mattanó
Courses Plus Student 12,188 PointsReport it as a bug