# Enum question(s)

**URL:** https://discussions.unity.com/t/enum-question-s/659515
**Category:** Scripting
**Tags:** Scripting
**Created:** [March 26, 2017, 11:33am UTC](https://discussions.unity.com/t/enum-question-s/659515 "2017-03-26T11:33:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AndrAla](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@AndrAla](https://discussions.unity.com/u/AndrAla)
#### Post date: [March 26, 2017, 11:33am UTC](https://discussions.unity.com/t/enum-question-s/659515/1 "2017-03-26T11:33:52Z")

</div>

I have few enums in my game, and I know that I can give them integer values:  
enum DamageType{  
physical = 0,  
magic = 1,  
fire = 2,  
…  
}  
and I know I can use these integer values by using (int)DamageType.physical (by putting an (int) before the enum). However, **how can I do it the other way around - I get the enum’s value by using an int**?  
And **can I get the amount of members the enum contains with a function**? (something like getting an array’s length)?  
Or perhaps **can I loop trough each member (by using for or while)**?

---

<div class="post-metadata">

### Author: ![Kona](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kona/32/105014_2.png) [@Kona](https://discussions.unity.com/u/Kona)
#### Post date: [March 26, 2017, 12:28pm UTC](https://discussions.unity.com/t/enum-question-s/659515/2 "2017-03-26T12:28:24Z")

</div>

You simply cast the integer value to your enum:

```csharp
DamageType dt = (DamageType)yourIntValue;

```

To get the length of an enum you use System.Enum like so:

```csharp
int enumLength = System.Enum.GetValues( typeof( DamageType )).Length;

```
