Question about Console Write() & WriteLine() methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Unemployed VC++ guy

    #1

    Question about Console Write() & WriteLine() methods

    It seems that there is basically no difference between the Console.Write() &
    String.Format() , other than the output being sent to the console output stream
    instead of a string. Is this accurate?

    String formatter = "(whatever) ";

    Console.Write(f ormatter,object 1,object2, ... );

    String formattedString = String.Format(f ormatter,object 1,object2, ... );

    // Basically, formattedString will be exactly the same as what was put to the
    console

    Also, is there any difference between Write() & WriteLine(), other than a new
    line?

    String thankU = "Thanks";
    Console.WriteLi ne(thankU);

  • Morten Wennevik

    #2
    Re: Question about Console Write() & WriteLine() methods

    Hi,

    I believe String.Format is mainly for backwards compatibility (or rather
    for people familiar with String.Format to begin with) as assembling
    complex strings in .net can be done by simple string concatenation and
    ToString() in a more readable manner.

    And no, WriteLine adds a linebreak at the end, otherwise they are the same.


    --
    Happy Coding!
    Morten Wennevik [C# MVP]

    Comment

    • MasterGaurav

      #3
      Re: Question about Console Write() & WriteLine() methods

      Yes. That's accurate.

      Console.Write/Line make use of String.Format internally to format the
      strings.

      --
      Cheers,
      Gaurav Vaish


      ----------------------------

      Comment

      Working...