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#

Jesse Mikkonen
Jesse Mikkonen
1,939 Points

Why not use Console.WriteLine(""); What's the difference between that and; System.Console.Write(""); ?

Difference between Console.WriteLine(""); and System.Console.Write("");?

3 Answers

Steven Parker
Steven Parker
231,248 Points

System.Console.Write puts out to the console exactly what you give it as a parameter. System.Console.WriteLine does the same thing, but it ALSO puts out an end of line (also known as "carriage return").

As you wrote them, with empty string parameters, System.Console.Write("") would do nothing. but System.Console.WriteLine("") would go to the next line.

I also noticed that you only included the System namespace on one of them. If your code includes a using System; directive, the System part becomes optional. Otherwise, you'd have to use the whole name of each of them for your code to compile correctly.

Jesse Mikkonen
Jesse Mikkonen
1,939 Points

Not System.Console.WriteLine, ditch the System from there. Or is it the same thing? If it is, why add the System? Nevertheless, thank you for the reply it clarifies things a little.

Steven Parker
Steven Parker
231,248 Points

System.Console.WriteLine is the same thing as Console.WriteLine, just as System.Console.Write is the same thing as Console.Write. You can optionally leave off the System. part as long as you have previously written using System;.

And remember to choose a "best answer". :)

Hi Jesse Not sure what exactly your point was, basically csharp/.net everything is inherited from System namespace.

System namespace contains fundamental classes and base classes that define commonly-used value and reference data types.You can view this System as a big parent class.

And Console class is one of many child classes it holds.

So typically if you are using Visual studio IDE, this namespace is always a default one when you create any csharp class or any other template.

Hope it gave some insight.

Steven Parker
Steven Parker
231,248 Points

The System namespace is not a default without using System;. That may be provided for you by Visual Studio, but not by the workspace here. If you leave that out, your references to Console methods will generate the compiler error: "CS0103: The name `Console' does not exist in the current context".

Hi Steven

Sure, As i was pointing when we use Visual Studio IDE, that comes as default depending on templates you select.

Regards Ravi.Challa