Solved

Enumeration Explanation of {0}

Posted on 2009-04-04
3
271 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

20 Experts available now in Live!

Get 1:1 Help Now