CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: C# Writeln

  1. #1
    Join Date
    Mar 2003
    Posts
    402

    C# Writeln

    I had a question with the writeln statement. I am kind of new to C#

    I was wondering if you could do something like this w/ the writeln statement

    To displat 2 integers you must do something like

    int i1,i2
    Console.Writeln(i1 + "==" + i2)

    However, is there a way to do something similiar to C
    int i1, i2
    Console.Writeln("%i==%i",i1,i2)


    Thanks

  2. #2
    Join Date
    Aug 1999
    Location
    Romania, Bucharest
    Posts
    253

    Re: C# Writeln

    take a look at this:

    Console.WriteLine("Tip total/rate:" + ControlChars.Tab + "{0,8:c} ({11})", tip, tipRate)

    let me know if this helps you

  3. #3
    Join Date
    Jan 2005
    Posts
    43

    Re: C# Writeln

    Yup,

    ----

    Console.WriteLine("{0} == {1}", i1, i2);

    ----

    just use { } around the number, or w/e in the order they appear after the comma.
    Last edited by MAL1C3; March 7th, 2005 at 03:53 PM.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: C# Writeln

    Quote Originally Posted by MAL1C3
    Console.WriteLine("{0} == {1}", i1, i2);

    just use { } around the number, or w/e in the order they appear after the comma.
    Well, you can specify any order you want:
    Code:
    int i1=1;
    int i2=2;
    int i3=3;
    Console.WriteLine("{0} - {2} - {1}", i1, i2, i3);
    Output:
    Code:
    1 - 3 - 2
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: C# Writeln

    That is legal too:
    Code:
     
    int i1=1;
    Console.WriteLine("{0} - {0}", i1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured