difference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vinnie

    #1

    difference

    If i write:

    double alfa = 10;

    Console.WriteLi ne("The number is {0}", alfa");

    it shows on the console: The number is 10.

    Now, what the meaning if i write:
    Console.WriteLi ne("The number is {0:xx}", alfa") ?

    I know it's incorrect, i just can't figure out what does the colon and
    the parameter xx may mean.

    Thanks

  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: difference

    Hi,

    Both lines will giv eyou error, there is an extra " at the end.

    Take a look at formatting in MSDN. It can get tricky at the beginning and
    the best way to get it is seeing examples.

    "vinnie" <centro.gamma@g mail.comwrote in message
    news:1189519645 .212602.101230@ r34g2000hsd.goo glegroups.com.. .
    If i write:
    >
    double alfa = 10;
    >
    Console.WriteLi ne("The number is {0}", alfa");
    >
    it shows on the console: The number is 10.
    >
    Now, what the meaning if i write:
    Console.WriteLi ne("The number is {0:xx}", alfa") ?
    >
    I know it's incorrect, i just can't figure out what does the colon and
    the parameter xx may mean.
    >
    Thanks
    >

    Comment

    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

      #3
      Re: difference

      vinnie wrote:
      If i write:
      >
      double alfa = 10;
      >
      Console.WriteLi ne("The number is {0}", alfa");
      >
      it shows on the console: The number is 10.
      >
      Now, what the meaning if i write:
      Console.WriteLi ne("The number is {0:xx}", alfa") ?
      >
      I know it's incorrect, i just can't figure out what does the colon and
      the parameter xx may mean.
      >
      Thanks
      The string that comes after the colon is a formatting string. You can
      for example use {0:N2}, which would format the number with two decimal
      places.

      Formatting overview:
      http://msdn2.microsoft.com/en-us/library/26etazsy.aspx

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      Working...