9 Replies - 9129 Views - Last Post: 25 October 2012 - 11:33 AM Rate Topic: -----

#1 stannee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-October 12

Difference between Console.Write and WriteLine

Posted 24 October 2012 - 12:03 PM

Hello all,

My name is stan and i'm new to the forum. After a few weeks of debating I've finally decided to take the plunge and commit myself to learning a programming and this has found me choosing C#. I started my tutorials today and in the first tutorial I was given this code:

class Order
{
    static void Main()
    {
        System.Console.WriteLine("Georgetown Dry Cleaning Services");
        System.Console.WriteLine("Learning C# starts today"); 
        System.Console.ReadKey();
    }
}



As I was typing ".WriteLine" I noticed there was another word ".Write" which after attempting out of curiosity I noticed that it does the same thing. My question is: what is the difference between these two?

Looking forward to your responses to this and many more of my questions, as I develop my programming skills.

Stan

Is This A Good Question/Topic? 0
  • +

Replies To: Difference between Console.Write and WriteLine

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9583
  • View blog
  • Posts: 36,319
  • Joined: 12-June 08

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 12:08 PM

Write line - adds a line terminator after the string.. write does not.


http://msdn.microsof....writeline.aspx
http://msdn.microsof...sole.write.aspx

A simple experiment outlines this:
        Console.Write("a");
        Console.Write("b");
        Console.Write("c");
        Console.Write("d");

        Console.WriteLine("1");
        Console.WriteLine("2");
        Console.WriteLine("3");
        Console.WriteLine("4");

Was This Post Helpful? 1
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5678
  • View blog
  • Posts: 12,216
  • Joined: 02-June 10

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 12:09 PM

All of these are described in the MSDN.
One of the easiest ways to reach the right MSDN page is to google "MSDN console.write" and "MSDN Console.WriteLine". The first link is the right link 99% of the time.

Open the two pages in different tabs or side-by-side browsers then compare the descriptions. You'll find these two commands do NO do the same thing. One writes a line, including line terminator (return/new line) the other does not.

So if you were to:

console.write("hello ");
console.write("world");


the console output would be: "hello world"
on one line
Was This Post Helpful? 1
  • +
  • -

#4 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 12:09 PM

This is write and this is writeline
Was This Post Helpful? 1
  • +
  • -

#5 stannee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-October 12

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 12:20 PM

Thank you for that, I shall give that a go and see how it pans out.

stan

View Postmodi123_1, on 24 October 2012 - 12:08 PM, said:

Write line - adds a line terminator after the string.. write does not.


http://msdn.microsof....writeline.aspx
http://msdn.microsof...sole.write.aspx

A simple experiment outlines this:
        Console.Write("a");
        Console.Write("b");
        Console.Write("c");
        Console.Write("d");

        Console.WriteLine("1");
        Console.WriteLine("2");
        Console.WriteLine("3");
        Console.WriteLine("4");


Thank you to all for the quick responses, they surely have given me more clarity as to the differences between the two.

Cheers,
Stan
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 12:45 PM

Let me throw this out there:

Please experiment! It's how most of us learned. You're not going to hurt anything by trying to use Write instead of WriteLine and seeing what's different. There's really only a few places where you have to be careful of experimenting (mostly with File I/O, you don't want to accidentally delete or overwrite something), because you really can't cause any damage accidentally.

Also, the MSDN is a wonderful resource for this kind of thing. A quick google of "C# Console.WriteLine" and "C# Console.Write" would have yielded you all the information you could possibly want to know about these two methods.

I'm not saying "just google it", but I am saying that you have access to one of the best sets of online documentation in the entire programming universe.

Also, I edited your post title. "C# beginner" isn't exactly a good title. It isn't descriptive of your question, and it is redundant (we're in the C# forum, I think we can figure out it's a C# question). Please be more descriptive with your titles in the future, it will help you get better and quicker assistance.
Was This Post Helpful? 1
  • +
  • -

#7 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 314
  • View blog
  • Posts: 490
  • Joined: 13-June 12

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 02:12 PM

In fact, to back up Curtis Rutland, experimentation is key. A good programmer will write decent code based on what he knows works. A great programmer will research and try a series of experiments to find out exactly how something works, its limitations, and when he should or shouldn't use it.

I spend less than 10% of my day writing code. The rest I spend testing it, and trying to break it.
Was This Post Helpful? 1
  • +
  • -

#8 stannee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-October 12

Re: Difference between Console.Write and WriteLine

Posted 24 October 2012 - 02:28 PM

Thank you Curtis & MrShoes for the feedback. It's really great to share a forum with helpful individuals, I've taken all the responses particularly those pertaining to the MSDN references and that off the constant need to practice and experiment with my code.
Was This Post Helpful? 0
  • +
  • -

#9 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 592
  • View blog
  • Posts: 1,322
  • Joined: 24-April 12

Re: Difference between Console.Write and WriteLine

Posted 25 October 2012 - 11:32 AM

View PostCurtis Rutland, on 25 October 2012 - 12:20 PM, said:

I'd be happy to debate this in deeper detail if you'd like, but let's not do it in someone's help thread. If you want, start a topic in the C# advanced discussion area.



Sorry. Just pointing out that it's more helpful to explain than point at Microsoft's worthless documentation for those who are just getting started.

(I'm probably just having a bad day because Windows 8 is out today and it looks like they are forcing all apps to be sold through the app store not to mention they still haven't explained what their plans for XNA and game development in C# are.) ;-)

Anyway, I'll leave the discussion at that.
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Difference between Console.Write and WriteLine

Posted 25 October 2012 - 11:33 AM

The previous replies here were veering tangential, so they were split and moved to their own thread:

http://www.dreaminco...-documentation/

If anyone would like to continue that line of discussion, please do so on the new thread. Let's keep Q/A threads clean.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1