Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:51:24+00:00 2026-06-12T13:51:24+00:00

I have an enum : public enum Fruits { Apple = 14, Lemon =

  • 0

I have an enum:

 public enum Fruits
    {
       Apple = 14,
       Lemon = 174,
       Grapes = 200,
       Peach = 1
    }

and a list by this enum:

IEnumerable<Fruits> Fruits = new List<Fruits>();

By default when I call getValues on the enum it sorts the entries by their id.
I show the list as a dropdown in the UI and want to sort the members of the list in specific order. In my sample I want Lemon to be the first item in the list.

I tried to order the items by the Lemon entry with something like this:

Fruits.OrderBy(f => f.Lemon);

but I am not allowed to do this f.Lemon in this context. Maybe I can foreach the list remove the Lemon item and then insert it as a first entry.

I am quite new to programming and I have found some similar questions but not with enum type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:51:26+00:00Added an answer on June 12, 2026 at 1:51 pm

    You can use OrderByDescending + ThenBy:

    fruits.OrderByDescending(f => f == Fruits.Lemon)
          .ThenBy(f => f);
    

    Note that the variable should have a different name than the enum type (I’ve used lowercase fruits).

    If you want to order second by the name:

          .ThenBy(f => f.ToString());
    

    f == Fruits.Lemon returns a bool which you can order by. It’s similar to SQL CASE:

    ORDER BY CASE WHEN Fruit = 'Lemon' THEN 1 ELSE 0 END DESC, FRUIT ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have enum class public enum CommandEnum { ADD_ITEM { { this.command = new
I have enum like this [Flags] public enum Key { None = 0, A
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
Suppose I have this enum: public enum TestEnum { EXAMPLE, FURTHER_EXAMPLE, LAST_EXAMPLE } With
Lets say you have this enum: Public Enum ApplicationStatus <Foo(Active)> Active = 1 <Foo(Inactive)>
I have the following enum public enum myEnum { ThisNameWorks, This Name doesn't work
I have enum like this public enum PetType { Dog = 1, Cat =
I have this enum: public enum ContentKey { Menu = 0, Article = 1,
I have an enum like this : public enum Priority { Low = 0,
I have enum like this public enum Sizes { Normal(232), Large(455); private final int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.