Solved

Enum, Switch

Posted on 2006-06-14
5
459 Views
Last Modified: 2010-04-16
Hi experts.

I would like to use an enum of roles to check against a int variable.

I have the following:

foreach(int roleId in currentUserRoles)
{
  switch(roleId)
  {
      case ((int)RoleType.Administrator):
             AdminOnly = true;
            break;
   }
}

what I need to happen is for an integer check to happen, but this does not seem to work. My enum is as follows:

public enum RoleType
{
    Operations = 0,
    Finance = 1,
    Administrator = 2
}

basically, whatever numbers are returned in roleId (1,3) then my code should check against the enum to see which role this links to then set a bool value respectively

Wayne
0
Comment
Question by:watherton
5 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 32 total points
ID: 16900819
I don't really see a problem in this code. It seems quite efficient to me. What is the exact problem?
0
 
LVL 13

Assisted Solution

by:dungla
dungla earned 31 total points
ID: 16900823
Hi watherton,

Your code is correct and should work. Can you tell me what kind of error you met?
0
 
LVL 4

Assisted Solution

by:jvn222
jvn222 earned 31 total points
ID: 16901007
Your code is correct and should work!

to dungla: Bac dungla van kiem diem a, thang nay bac moi duoc co 1000 thoi a? :D
0
 
LVL 10

Assisted Solution

by:SystemExpert
SystemExpert earned 31 total points
ID: 16901042
Hi,

I think you need like this

foreach(int roleId in currentUserRoles)
{
      if (roleId==(int)RoleType.Administrator)
      {
            AdminOnly = true;
            break;
      }
                        
}

Thanks
0
 

Author Comment

by:watherton
ID: 16901074
my mistake,

thanks for the help chaps, it worked fine.

I will split the points
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

14 Experts available now in Live!

Get 1:1 Help Now