---
title: "Converting enum to int in C#"  
description: "Converting enum to int in C#"  
author: "Steilla Mitchel"  
published: 2023-08-17  
updated: 2023-08-18  
canonical: https://www.mindstick.com/forum/159565/converting-enum-to-int-in-c-sharp  
category: "c#"  
tags: ["c#", "list"]  
reading_time: 2 minutes  

---

# Converting enum to int in C#

Converting [enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum) to [int](https://www.mindstick.com/forum/159137/how-to-convert-date-int-to-date-in-sql) in C#

## Replies

### Reply by Aryan Kumar

There are two ways to convert an enum to an int in C#:

1. Using the `ToInt()` method.
2. Using the `value` property.

**Using the** `ToInt()` **method**

The `ToInt()` method takes an enum as its parameter and returns the corresponding integer value. The following code converts an enum to an int:

C#

```plaintext
enum Color { Red, Green, Blue }

int red = (int)Color.Red;
```

In this code, the `ToInt()` method is used to convert the `Color.Red` enum to an int. The result is the integer value 0, which is the underlying value of the `Color.Red` enum.

**Using the** `value` **property**

The `value` property of an enum returns the underlying integer value of the enum. The following code also converts an enum to an int:

C#

```plaintext
enum Color { Red, Green, Blue }

int red = Color.Red.value;
```

In this code, the `value` property of the `Color.Red` enum is used to get the underlying integer value, which is 0.

Which method you use to convert an enum to an int depends on your preference. The `ToInt()` method is more explicit, as it explicitly specifies that you are converting the enum to an int. However, the `value` property is more concise and easier to read.


---

Original Source: https://www.mindstick.com/forum/159565/converting-enum-to-int-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
