difference

  • Thread starter Thread starter vinnie
  • Start date Start date
V

vinnie

If i write:

double alfa = 10;

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

it shows on the console: The number is 10.

Now, what the meaning if i write:
Console.WriteLine("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
 
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 said:
If i write:

double alfa = 10;

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

it shows on the console: The number is 10.

Now, what the meaning if i write:
Console.WriteLine("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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top