c# Programming Glossary: enum.getvalues
How do I enumerate an enum in C#? http://stackoverflow.com/questions/105372/how-do-i-enumerate-an-enum-in-c
How do I convert an enum to a list in C#? [duplicate] http://stackoverflow.com/questions/1167361/how-do-i-convert-an-enum-to-a-list-in-c an IEnumerable SomeEnum of all the values of an Enum. Enum.GetValues typeof SomeEnum .Cast SomeEnum If you want that to be a List..
Search for a string in Enum and return the Enum http://stackoverflow.com/questions/2290262/search-for-a-string-in-enum-and-return-the-enum string colours Enum.GetNames typeof MyColours int values Enum.GetValues typeof MyColours int i for int i 0 i colours.Length i if colour.Equals..
How to get C# Enum description from value? [duplicate] http://stackoverflow.com/questions/2650080/how-to-get-c-sharp-enum-description-from-value to write code like var myEnumDescriptions from MyEnum n in Enum.GetValues typeof MyEnum select new ID int n Name Enumerations.GetEnumDescription..
Get enum from enum attribute http://stackoverflow.com/questions/2787506/get-enum-from-enum-attribute string value Type enumType typeof Als foreach Enum val in Enum.GetValues enumType FieldInfo fi enumType.GetField val.ToString StringValueAttribute..
Finding an enum value by its Description Attribute [duplicate] http://stackoverflow.com/questions/3422407/finding-an-enum-value-by-its-description-attribute Using the extension method described here Testing t Enum.GetValues typeof Testing .Cast Testing .FirstOrDefault v v.GetDescription..
Iterate over values in Flags Enum? http://stackoverflow.com/questions/4171140/iterate-over-values-in-flags-enum bit values in that specific variable Or do I have to use Enum.GetValues to iterate over the entire enum and check which ones are set.. Enum GetFlags this Enum value return GetFlags value Enum.GetValues value.GetType .Cast Enum .ToArray public static IEnumerable.. Type enumType ulong flag 0x1 foreach var value in Enum.GetValues enumType .Cast Enum ulong bits Convert.ToUInt64 value if bits..
MVC3 Razor DropDownListFor Enums http://stackoverflow.com/questions/4656758/mvc3-razor-dropdownlistfor-enums items new List SelectListItem foreach var item in Enum.GetValues enumType FieldInfo fi enumType.GetField item.ToString var..
C# Iterating through an enum? (Indexing a System.Array) http://stackoverflow.com/questions/482729/c-sharp-iterating-through-an-enum-indexing-a-system-array the values of all the elements within myEnum Array values Enum.GetValues typeof myEnum Print the names and values to file for int i 0.. system.array share improve this question Array values Enum.GetValues typeof myEnum foreach MyEnum val in values Console.WriteLine.. names Enum.GetNames typeof MyEnum MyEnum values MyEnum Enum.GetValues typeof MyEnum for int i 0 i names.Length i print names i values..
Create drop down list options from enum in a DataGridView http://stackoverflow.com/questions/56443/create-drop-down-list-options-from-enum-in-a-datagridview column but it works with ComboBoxes comboBox1.DataSource Enum.GetValues typeof MyEnum and MyEnum value MyEnum comboBox1.SelectedValue.. col.Name My Enum Column col.DataSource Enum.GetValues typeof MyEnum col.ValueType typeof MyEnum dataGridView1.Columns.Add..
Create Generic method constraining T to an Enum http://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum value return defaultValue foreach T item in Enum.GetValues typeof T if item.ToString .ToLower .Equals value.Trim .ToLower.. value return defaultValue foreach T item in Enum.GetValues typeof T if item.ToString .ToLower .Equals value.Trim .ToLower..
Can You Loop Through All Enum Values? [duplicate] http://stackoverflow.com/questions/972307/can-you-loop-through-all-enum-values question Yes you can use the GetValues method var values Enum.GetValues typeof Foos Or the typed version var values Enum.GetValues typeof.. Enum.GetValues typeof Foos Or the typed version var values Enum.GetValues typeof Foos .Cast Foos I long ago added a helper function to.. EnumUtil public static IEnumerable T GetValues T return Enum.GetValues typeof T .Cast T Usage var values EnumUtil.GetValues Foos ..
|