Solved

Enumeration Explanation of {0}

Posted on 2009-04-04
3
273 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 225 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 25 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now