?
Solved

Enumeration Explanation of {0}

Posted on 2009-04-04
3
Medium Priority
?
290 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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