---
title: "Get enum from enum attribute"  
description: "Get enum from enum attribute"  
author: "Anonymous User"  
published: 2013-12-09  
updated: 2013-12-09  
canonical: https://www.mindstick.com/forum/1761/get-enum-from-enum-attribute  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Get enum from enum attribute

public [enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum) Als

{

[StringValue("Beantwoord")] Beantwoord = 0,

[StringValue("Niet beantwoord")] NietBeantwoord = 1,

[StringValue("Geselecteerd")] Geselecteerd = 2,

[StringValue("Niet geselecteerd")] NietGeselecteerd = 3,

}

public [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) StringValueAttribute : [Attribute](https://www.mindstick.com/blog/221/attributes-reflection)

{

[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) string _value;

public StringValueAttribute([string value](https://www.mindstick.com/forum/159623/how-to-get-an-enum-value-from-a-string-value-in-c-sharp))

{

_value = value;

}

public string Value

{

get { return _value; }

}

}

And I would like to put the value from the [item](https://www.mindstick.com/forum/156564/remove-item-in-an-array-in-javascript) I selected of a [combobox](https://www.mindstick.com/articles/57/display-record-according-to-combobox-selection-in-csharp-dot-net) into a int:

int i = (int)(Als)Enum.Parse(typeof(Als), (string)cboAls.SelectedValue); //<- [WRONG](https://answers.mindstick.com/qa/48468/who-wrote-the-the-wrong-enemy-america-in-afghanistan-2001-2014-and-when)

Is this possible, and if so, how? (the StringValue matches the value selected from the combobox).

## Replies

### Reply by Anonymous User

Hi Pravesh,\

I'm using the DescriptionAttribute from Microsoft and the following extension method:

```
public static string GetDescription(this Enum value){    if (value == null)    {        throw new
ArgumentNullException("value");    }    string description
= value.ToString();    FieldInfo
fieldInfo = value.GetType().GetField(description);   
DescriptionAttribute[] attributes =      
(DescriptionAttribute[])    
fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);    if (attributes !=
null && attributes.Length > 0)    {        description =
attributes[0].Description;    }    return
description;}
```


---

Original Source: https://www.mindstick.com/forum/1761/get-enum-from-enum-attribute

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
