Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Enumeration Explanation of {0}

Posted on 2009-04-04
3
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

647 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