---
title: "Sort enums in declaration order"  
description: "Sort enums in declaration order"  
author: "Manoj Bhatt"  
published: 2014-08-14  
updated: 2014-08-14  
canonical: https://www.mindstick.com/forum/2038/sort-enums-in-declaration-order  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Sort enums in declaration order

```
public enum CurrencyId{    USD = 840,    UAH = 980,    RUR = 643,    EUR = 978,    KZT = 398,    UNSUPPORTED = 0}
```

Is there any way to sort [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) of [Enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum).GetValues(typeof(CurrencyId)).Cast<CurrencyId>() by [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) they are declared in .cs [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) (USD, UAH, RUR, [EUR](https://answers.mindstick.com/qa/37455/when-will-eur-usd-trading-start-in-india), KZT, UNSUPPORTED), not by their underlying [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)? Personally, I believe the answer is 'no', because original order is lost in binaries, so... how can I implement the [task](https://www.mindstick.com/forum/161761/what-is-the-difference-between-task-and-thread)?

## Replies

### Reply by Pravesh Singh

Hi Manoj, try this:\

```
using System;using System.Reflection;public class Test{    public enum CurrencyId {        USD = 840,        UAH = 980,        RUR = 643,        EUR = 978,        KZT = 398,        UNSUPPORTED =0    }    public static void Main()    {       
foreach(FieldInfo fi in typeof(CurrencyId).GetFields())           
if(fi.IsStatic) Console.WriteLine(fi.Name);    }}
```

## Output:

USD

UAH

RUR

EUR

KZT


---

Original Source: https://www.mindstick.com/forum/2038/sort-enums-in-declaration-order

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
