Manish Pansiniya’s Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Iterate through Enumeration C#

with 8 comments

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 :P

Written by Manish

September 27, 2007 at 12:56 pm

Posted in .NET

8 Responses

Subscribe to comments with RSS.

  1. one line:
    foreach(MyEnum in Enum.GetValues(typeof(MyEnum)))

    Anonymous

    January 8, 2008 at 4:52 pm

  2. Excellent solution buddy

    Nazir

    March 19, 2008 at 6:45 am

  3. thx, its simple

    Anonymous

    April 25, 2008 at 8:38 am

  4. 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

  5. foreach(SiteHelper.CurrenyList objCurrency in Enum.GetValues(typeof(SiteHelper.CurrenyList)))
    {
    Label1.Text = Label1.Text + objCurrency.ToString();
    }

    aa

    September 14, 2008 at 11:27 am

  6. // 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

  7. // 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

  8. 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


Leave a Reply