Click here to Skip to main content
15,917,455 members
Home / Discussions / C#
   

C#

 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Luc Pattyn9-Jul-07 8:20
sitebuilderLuc Pattyn9-Jul-07 8:20 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Luc Pattyn9-Jul-07 8:44
sitebuilderLuc Pattyn9-Jul-07 8:44 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Shy Agam9-Jul-07 8:51
Shy Agam9-Jul-07 8:51 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Martin#9-Jul-07 9:06
Martin#9-Jul-07 9:06 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Luc Pattyn9-Jul-07 9:18
sitebuilderLuc Pattyn9-Jul-07 9:18 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Luc Pattyn9-Jul-07 9:27
sitebuilderLuc Pattyn9-Jul-07 9:27 
GeneralRe: Iterating through all values of an ORed enum variable... Pin
Martin#9-Jul-07 9:54
Martin#9-Jul-07 9:54 
AnswerRe: Iterating through all values of an ORed enum variable... Pin
PhilDanger9-Jul-07 7:17
PhilDanger9-Jul-07 7:17 
Well, I don't know how to iterate through all POSSIBLE values of an enum, but given that you say you do, I think I have a solution for you.

Keys keys = Keys.Control | Keys.A;
foreach(Keys key in POSSIBLEVALUES){ //however you're managing that
   if(keys & key) == key){ //the key contains this one!

    }
}


Note: the enum value have to be lined up in powers of 2 in order for this to work properly so you can distinguish the values when you do a bitwise-or.

The following is a bit of code that shows this:

enum Keys
        {
            A = 1,
            B = 2,
            C = 4,
            D = 8
        }

        static void Main(string[] args)
        {
            Keys keys = Keys.A | Keys.B | Keys.D;
            if ((keys & Keys.A) == Keys.A)
            {
                Console.WriteLine("A");
            }
            if ((keys & Keys.B) == Keys.B)
            {
                Console.WriteLine("B");
            }
            if ((keys & Keys.C) == Keys.C)
            {
                Console.WriteLine("C");
            }
            if ((keys & Keys.D) == Keys.D)
            {
                Console.WriteLine("D");
            }

GeneralRe: Iterating through all values of an ORed enum variable... Pin
Shy Agam9-Jul-07 8:02
Shy Agam9-Jul-07 8:02 
AnswerRe: Iterating through all values of an ORed enum variable... Pin
PhilDanger9-Jul-07 10:55
PhilDanger9-Jul-07 10:55 
QuestionHow to play at the same time 2 or more sounds Pin
mayhem709-Jul-07 4:58
mayhem709-Jul-07 4:58 
AnswerRe: How to play at the same time 2 or more sounds Pin
mav.northwind9-Jul-07 19:21
mav.northwind9-Jul-07 19:21 
AnswerRe: How to play at the same time 2 or more sounds Pin
Hesham Yassin9-Jul-07 22:38
Hesham Yassin9-Jul-07 22:38 
Questionhow to sort datagridview ? (a numeric field) Pin
cmpeng349-Jul-07 4:53
cmpeng349-Jul-07 4:53 
AnswerRe: how to sort datagridview ? (a numeric field) Pin
velkropie9-Jul-07 6:24
velkropie9-Jul-07 6:24 
AnswerRe: how to sort datagridview ? (a numeric field) Pin
Luc Pattyn9-Jul-07 7:12
sitebuilderLuc Pattyn9-Jul-07 7:12 
QuestionHow do I Marshal Vector using Pinvoke Pin
Subodh Borker9-Jul-07 4:41
Subodh Borker9-Jul-07 4:41 
QuestionCrystal Reports Gurus - need help - please Pin
Rome'9-Jul-07 4:27
Rome'9-Jul-07 4:27 
QuestionUdp client Programming Pin
ramdil9-Jul-07 3:57
ramdil9-Jul-07 3:57 
AnswerRe: Udp client Programming Pin
Jimmanuel9-Jul-07 4:18
Jimmanuel9-Jul-07 4:18 
GeneralRe: Udp client Programming Pin
ramdil9-Jul-07 4:41
ramdil9-Jul-07 4:41 
GeneralRe: Udp client Programming Pin
Jimmanuel9-Jul-07 4:52
Jimmanuel9-Jul-07 4:52 
GeneralRe: Udp client Programming Pin
Luc Pattyn9-Jul-07 5:05
sitebuilderLuc Pattyn9-Jul-07 5:05 
GeneralRe: Udp client Programming Pin
ramdil9-Jul-07 5:12
ramdil9-Jul-07 5:12 
GeneralRe: Udp client Programming Pin
Jimmanuel9-Jul-07 5:20
Jimmanuel9-Jul-07 5:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.