Example

The following example demonstrates the use of two types of enumerations, one with the Flags attribute applied and one without. It is fair to say, however, that use of the attribute is a little contrived in this sample.

 using System; namespace Samples { public class EnumToString { enum DayOfWeek {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; [Flags] enum MonthOfYear {January = 0x1, February = 0x2, March = 0x4, April = 0x8, May = 0x10, June = 0x20, July = 0x40, August = 0x80, September = 0x100, Ocotber = 0x200, November = 0x400, December = 0x800}; public static void Main() { string[] f = {"D", "F", "X", "G"}; DayOfWeek d = DayOfWeek.Saturday; foreach(string s in f) Console.WriteLine( "Value {0} formatted with {1}: {2}", ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.