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) Console I/O Formatting Output

How to solve the problem of the concatenation code in the exam

i wrote the code in the right format but i dont know why the compiler makes error

CodeChallenge.cs
using System;
string firstName;
firstName = Console.ReadLine();
//firstName = firstName +  " rocks !"
System.Console.WriteLine(firstName +  " rocks !");


//Console.WriteLine( " rocks !"  );

3 Answers

Sebastian Wilson
Sebastian Wilson
15,710 Points

The answer below works

There is no space between rocks and the ! but there is a space before hand. So it's " rocks!" Not "rocks !"

var firstName = Console.ReadLine();

Console.WriteLine(firstName + " rocks!");

thank you Sebastian it works

Kjetil Lorentzen
Kjetil Lorentzen
13,360 Points

The code challenges are extremely sensitive when entering the text they ask for. In your case you should enter " rocks!" Instead of " rocks !".

Also, for the code challenge the using System directive is not necessary.

string firstName = Console.ReadLine();

Console.WriteLine(firstName + " rocks!");
Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi! I got your request to answer, but see that two others have done a great job already. To reiterate what they've said, challenges are very strict and when they ask for you to do something your output (generally speaking) must be exactly as they want it to the letter. This includes capitalization, punctuation, spelling, and even spacing.

Kjetil Lorentzen is correct. There is no need for the using directive. This is what is causing your compiler error.

Tip :bulb: Going forward into the challenges it's important to try not to do anything the challenge doesn't explicitly ask for. Even if functional outside the challenge, it can cause the challenge to fail.

Happy coding! :sparkles: