?
Solved

Enumeration Explanation of {0}

Posted on 2009-04-04
3
Medium Priority
?
300 Views
Last Modified: 2012-05-06
I was wondering I've seen enumeration values accessed and output in two ways one was by array/element notation and the other which included {0}, {1} could someone give me a detailed explanation of this from the following code example.

I understand that there's some value swopping going on but I'm not sure I understand why.  I've search msdn but to no avail.
using System;
public class EnumTest 
{
    enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
 
    static void Main() 
    {
        int x = (int)Days.Sun;
        int y = (int)Days.Fri;
        Console.WriteLine("Sun = {0}", x);
        Console.WriteLine("Fri = {0}", y);
    }
}

Open in new window

0
Comment
Question by:kvigor
3 Comments
 
LVL 22

Accepted Solution

by:
pivar earned 900 total points
ID: 24069036
Hi,

{0} is just a placeholder to show how you want to format the output from WriteLine with value x (or y). This will show the enum value as an int (since it'sconverted to an int) after the dayname. In this case "Sun=2" and "Fri=7".

Look here
http://msdn.microsoft.com/en-us/library/txafckwd(VS.71).aspx


/peter
0
 
LVL 4

Assisted Solution

by:brawney
brawney earned 100 total points
ID: 24069642
To expand on pivar's answer...  it is a placeholder to indicate what parameter you're passing to the WriteLine function.  Another example:

Console.WriteLine("Sun={0} and Fri={1}", x, y);

would print

Sun=2 and Fri=7

0
 

Author Closing Comment

by:kvigor
ID: 31566650
Very Well Done, I appreciate the responsiveness conciseness of your answers
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question