---
title: "Get the int value from the enum in C#"  
description: "Get the int value from the enum in C#"  
author: "Utpal Vishwas"  
published: 2023-08-21  
updated: 2023-08-23  
canonical: https://www.mindstick.com/forum/159627/get-the-int-value-from-the-enum-in-c-sharp  
category: "c#"  
tags: ["c#", "enum"]  
reading_time: 2 minutes  

---

# Get the int value from the enum in C#

Get the [int](https://www.mindstick.com/forum/159137/how-to-convert-date-int-to-date-in-sql) [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) from the [enum in C#](https://www.mindstick.com/forum/33625/how-to-use-enum-in-c-sharp-dot-net)

## Replies

### Reply by Aryan Kumar

Sure, here's how you can get the int value from an [enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum) in C#:

C#

```plaintext
enum MyEnum {
  Value1 = 1,
  Value2 = 2,
  Value3 = 3
}

MyEnum myEnum = MyEnum.Value1;

// Get the int value from the enum.
int myInt = (int)myEnum;
```

In this example, the `myEnum` variable is an enum that is initialized to the value of `Value1`. The `(int)myEnum` cast operator casts the `myEnum` variable to an int. The value of the `myInt` variable is now 1.

You can also use the `Enum.ToInt32()` method to get the int value from an enum. Here's how you can do it:

C#

```plaintext
enum MyEnum {
  Value1 = 1,
  Value2 = 2,
  Value3 = 3
}

MyEnum myEnum = MyEnum.Value1;

// Get the int value from the enum using the Enum.ToInt32() method.
int myInt = Enum.ToInt32(myEnum);
```

In this example, the `myEnum` variable is an enum that is initialized to the value of `Value1`. The `Enum.ToInt32(myEnum)` method casts the `myEnum` variable to an int. The value of the `myInt` variable is now 1.

Which method you use depends on your specific needs. If you need to cast an enum to an int and you don't need to do any further processing on the int value, then the cast operator is a good option. If you need to do further processing on the int value, then the `Enum.ToInt32()` method is a good option.


---

Original Source: https://www.mindstick.com/forum/159627/get-the-int-value-from-the-enum-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
