I saw somewhere (cannot find it anymore) that you can check the existence of an enum value from an enum item with a specific list of items. Ex. below - "Available = doc | xls | csv"
But the following code does not seem to work. I'm expecting the results to be = xls instead of doc, since it is in the list of "Available" values.
Can someone please help?
Thanks in advance!
Niki
Button Code:
protected void btnTest01_Click(object sender, EventArgs e) { TestEnum01 result1 = TestEnum01.xls; TestEnum02 result2 = TestEnum02.xls; TestEnum03 result3 = TestEnum03.xls; if (result1 != TestEnum01.Available) { result1 = TestEnum01.doc; } if (result2 != TestEnum02.Available) { result2 = TestEnum02.doc; } if (result3 != TestEnum03.Available) { result3 = TestEnum03.doc; } this.txtTest01_Results.Text = String.Format("01: Result = {0}, Available = {1}\r\n\r\n02: Result = {2}, Available = {3}\r\n\r\n03: Result = {4}, Available = {5}", result1.ToString(), TestEnum01.Available, result2.ToString(), TestEnum02.Available, result3.ToString(), TestEnum03.Available); } ENUMS
public enum TestEnum01 { doc = 1, txt = 2, xls = 4, csv = 8, unknown = 5, Available = doc | xls | csv } public enum TestEnum02 { doc, txt, xls, csv, unknown, Available = doc | xls | csv } public enum TestEnum03 { doc, txt, xls, csv, unknown, Available = TestEnum03.doc | TestEnum03.xls | TestEnum03.csv } RESULTS:
01: Result = doc, Available = Available 02: Result = doc, Available = csv 03: Result = doc, Available = csv
if(result.HasFlag(TestEnum01.xls))and to get niceToStringconversion, useFlagsAttribute