Iterate through Enumeration C#
First create the array using following code:
Array lstProvider = System.Enum.GetValues( typeof(CommonShared.EnumProvider)); Then you can directly call the following foreach loop:
foreach (CommonShared.EnumProvider enProvider in lstProvider)
{}
Simple huh
one line:
foreach(MyEnum in Enum.GetValues(typeof(MyEnum)))
Anonymous
January 8, 2008 at 4:52 pm
Excellent solution buddy
Nazir
March 19, 2008 at 6:45 am
thx, its simple
Anonymous
April 25, 2008 at 8:38 am
example
foreach(SiteHelper.CurrenyList objCurrency in Enum.GetValues(typeof(SiteHelper.CurrenyList)))
{
Label1.Text = Label1.Text + bba.ToString();
}
aa
September 14, 2008 at 11:26 am
foreach(SiteHelper.CurrenyList objCurrency in Enum.GetValues(typeof(SiteHelper.CurrenyList)))
{
Label1.Text = Label1.Text + objCurrency.ToString();
}
aa
September 14, 2008 at 11:27 am
// Here is how you retrieve the integer value of the enumeration
foreach( MyEnum objEnum
in Enum.GetValues(typeof(AppealsWorkflow)) )
{
// Retrieve integer value of enumeration
intTemp = System.Convert.ToInt32(
Enum.Parse(typeof(MyEnum),objEnum.ToString()));
Skip Cherniss
October 7, 2008 at 9:50 pm
// Just to add something, Here is how you Iterate with Enum Argument.
public void ParseRequiredFields(Enum oBankEnum)
{
System.Type oBankEnumType = oBankEnum.GetType();
foreach (String objBankEnum in System.Enum.GetNames(oBankEnumType))
{
objBankEnum.ToString();
}
}
Jet
February 10, 2009 at 8:27 am
Jet, thank you very much for the followup coding. That was exactly what I was looking for.
PaulN
February 17, 2009 at 8:49 pm