Assuming the following definitions:
[Flags]
enum Days {
Sunday = 1,
Monday = 2,
Tuesday = 4,
Wednesday = 8,
Thursday = 16,
Friday = 32,
Saturday = 64
}
[Flags]
enum WeekOfMonth {
First = 256,
Second = 512,
Third = 1024,
Fourth = 2048
}
You can get the desired string using this code:
var value = (Int32) WeekOfMonth.Second + (Int32) Days.Monday; // 514
var days = (Days) (value & 0xFF);
var weekOfMonth = (WeekOfMonth) (value & 0xFF00);
var str = String.Format("{0} & {1}", weekOfMonth, days);
The variable str
will contain Second & Monday
as desired.
The [Flags]
attribute is important if you want to be able to combine several Days
values or WeekOfMonth
values. For instance ((Days) 3).ToString()
will return Sunday, Monday
. If you forget the [Flags]
attribute the string returned is 3
.