Solved

switch statement using an enum

Posted on 2007-11-30
1
2,712 Views
Last Modified: 2012-05-05
Can you not use a straight enum in a switch statement?

It seems i have to cast it:

    public enum blah
    {
        p,b,s
    }

    public void dosomething(blah h)
    {
        switch (h)  // CANNOT DO THIS?
        {
            case 1:
                break;
            case 2:
                break;
            default:
                break;
        }


        switch ((int)h)  // THIS IS OKAY
        {
            case 1:
                break;
            case 2:
                break;
            default:
                break;
        }

    }

0
Comment
Question by:knowlton
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20385545
you can, but you have to use the enum names instead of numerical values in the case part...

 public void dosomething(blah h)

    {
        switch (h)  
        {
            case p:
                break;
            case b:
                break;
            default:
                break;
        }

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn on intranet settings 1 56
C#  Radio button search for Date not DateTime 4 46
ASP.net Show "please wait " message as page loads 2 39
asp enable view state 1 24
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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