// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections; using System.Collections.Generic; namespace E { public class Program { [Flags] private enum e { A=1, B=2, C=4, D=8, E=16 } private static string[] sa = { "A", "B", "C", "D", "E" }; public static void Main(string[] args) { int v = 11; // BitArray BitArray ba = new BitArray(new int[] { v }); for(int i = 0; i < 32; i++) { if(ba[i]) { Console.WriteLine(sa[i]); // or add to List } } // enum foreach(e ev in e.GetValues(typeof(e))) { if((v & (int)ev) != 0) { Console.WriteLine(ev); // or add to List } } } } }