---
title: "Convert int to enum in C#"  
description: "Convert int to enum in C#"  
author: "Steilla Mitchel"  
published: 2024-06-11  
updated: 2024-06-11  
canonical: https://www.mindstick.com/forum/160707/convert-int-to-enum-in-c-sharp  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 2 minutes  

---

# Convert int to enum in C#

[Convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) [int](https://www.mindstick.com/forum/159137/how-to-convert-date-int-to-date-in-sql) to [enum in C#](https://www.mindstick.com/forum/33625/how-to-use-enum-in-c-sharp-dot-net)

## Replies

### Reply by Ravi Vishwakarma

You can convert an int value to an enumeration ([enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum)) type using type casting or the **Enum.Parse** method. \
Here's how you can do it:

#### Type Casting

You can directly cast an int to the enum type if the integer value corresponds to one of the defined enum values.

```cs
enum MyEnum {
    Value1,
    Value2,
    Value3
}

class Program {
    static void Main(string[] args) {
        int intValue = 2;
        MyEnum enumValue = (MyEnum)intValue;
        Console.WriteLine(enumValue); // Output: Value3
    }
}
```

#### Enum.Parse Method

If you need to convert an int value to an enum and you're not sure if the integer value corresponds to a valid enum value, you can use the **Enum.Parse** method.

```cs
enum MyEnum {
    Value1,
    Value2,
    Value3
}

class Program {
    static void Main(string[] args) {
        int intValue = 2;
        MyEnum enumValue = (MyEnum)Enum.Parse(typeof(MyEnum), intValue.ToString());
        Console.WriteLine(enumValue); // Output: Value3
    }
}
```

#### Convert.ChangeType Method

You can also use the **Convert.Change**Type method if you prefer.

```cs
enum MyEnum {
    Value1,
    Value2,
    Value3
}

class Program {
    static void Main(string[] args) {
        int intValue = 2;
        MyEnum enumValue = (MyEnum)Convert.ChangeType(intValue, typeof(MyEnum));
        Console.WriteLine(enumValue); // Output: Value3
    }
}
```


---

Original Source: https://www.mindstick.com/forum/160707/convert-int-to-enum-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
