views:

620

answers:

4

I have an eum type with 5 members. Is it possible to tell intellisense to order them the way I want?

public enum numbers
{
    zero,
    one,
    two,
    three,
    four
}

Intelisense shows (in alpha):

four
one
three
two
zero
+7  A: 

No you can't as far as I know. Intellisense orders them alphabetically.

Jamie Ide
+5  A: 

I think the only way to do that would be to do something like

public enum numbers
{
    num_00,
    num_01,
    num_02,
    num_03,
    num_04
}
Jason Down
+1  A: 

well if you use this kind of declaration for enum intellisense will sort by the first character

by diffrewnt kind of declartion i mean you can start the enum like _0 _1 _2 like that where _ will have the same previlage and then 0 1 2 etc will be used to reorder it.

Meetu Choudhary
Are you suggesting a different kind of declaration? Actually in my code I assign them all in values but I see the same thing in intellisense.
TheSean
by diffrewnt kind of declartion i mean you can start the enum like _0_1_2like that where _ will have the same previlage and then 0 1 2 etc will be used to reorder it.
Meetu Choudhary
+5  A: 

No you cant. But the Visual Studio team has considered the suggestion even though not exactly the way you would want it. But hey, its a start.

See the Microsoft connect response here http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=419602

I have added your requirement as a comment on the site.

Bobby Alexander
Too bad they aren't thinking of doing something like letting you put an attribute on your declaration to indicate the sort order (maybe alphabetical, value (like the underlying numerical value associated with the enumeration members), plus a few others maybe).
Jason Down
Great, thanks! I would like to see it as an attribute as well.
TheSean
Would you mind suggesting the attribute idea Bobby (since you are already a member of that community)? Unless of course you think the idea is crap =)
Jason Down
No, I think the idea is perfectly reasonable. I'll put in the idea as a comment.
Bobby Alexander
Thank you very much!
Jason Down
Jason, I have added your suggestion as a comment.
Bobby Alexander