Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public enum AccountCategory
   {
       [EnumMember]
       System_Owner = 2,
       [EnumMember]
       System_Account = 3,
       [EnumMember]
       Customer = 4,
       [EnumMember]
       Supplier = 5
   }


C#
public enum MainFeatures
    {
        /// <summary>
        /// No attribute set
        /// </summary>
        [EnumMember]
        NotSet = 0,
        /// <summary>
        /// Owner reference
        /// </summary>
        [EnumMember]
        Owner_Reference = 1,

}

What I have tried:

i tried only below code to get the list of enums
var value=enums.tolist();
Posted
Updated 25-Apr-16 4:11am

Your code Like :
C#
var value=Enum.GetValues(typeof(YourEnum)).Cast<yourenum>().ToList(); 
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 25-Apr-16 8:43am    
5 , should be Cast < yourenumType > ()
Mahesh_Bhosale 25-Apr-16 8:48am    
..??????
Karthik_Mahalingam 25-Apr-16 8:56am    
var value = Enum.GetValues(typeof(MyEnum)).Cast<int>().ToList();
awaisshabir 25-Apr-16 9:15am    
i only need below formate
AccountCategory,
MainFeatures
have a look on this for Enum reference

C#
enum EnumRank
       {
           First=1,
           Second=2,
           Third=3

       }
       static void Main(string[] args)
       {
           //To Get the list of enum Values
           List<int> Numbers = Enum.GetValues(typeof(EnumRank)).Cast<int>().ToList();  // 1,2 3

           //To Get the List of Enum Names
           List<string> Names = Enum.GetNames(typeof(EnumRank)).ToList();  //First, Second, Third

           // Cast Enum to a string
           EnumRank value = EnumRank.First;
           string name = Enum.GetName(typeof(EnumRank), value); // First

           // Cast a string value to Enum Object
           string enumInString = "Third";
           EnumRank enumValue = (EnumRank)Enum.Parse(typeof(EnumRank), enumInString); // Third Enum

       }
 
Share this answer
 
v2
Solutions 1 and 2 are incomplete. The trouble starts when some enumeration members have the same integer value (which is often needed). Anyway, these approached don't give you enumeration type members as you define them.

For the detailed explanations and a comprehensive solution, please see my article: Enumeration Types do not Enumerate! Working around .NET and Language Limitations.

For additional features, please see three more articles of my enumeration series, referenced in the "Introduction" section.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900