Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Legacy code has this enum declaration:

public enum ChangeListTypes
{
    Always = 1,
    Never = 2,
    CostChange = 3,
    None = 0
}

I would have done it this way:

public enum ChangeListTypes
{
    None = 0
    Always = 1,
    Never = 2,
    CostChange = 3,
}

Does it matter? Am I just being a curmudgeon, or is it better to order them as I normally do?

share|improve this question
    
I personally like your way, makes more sense, and you can actually remove the declarations. –  Jeff Vanzella Feb 25 '13 at 23:09
1  
Related: diranieh.com/NETCSharp/… which is one more reason for 0 value to be at the top. –  Leonid Feb 26 '13 at 1:01
1  
@Leonid your article (absolutely correctly) describes the reason for 0 to be present in enum. But it doesn't matter where it is declared, so Jesse's answer is absolutely correct. –  almaz Feb 26 '13 at 7:53
add comment

1 Answer

  1. It doesn't matter from a syntactical standpoint at all.

  2. I prefer your style - the None value of 0 should always go first. Very readable. Further, I also prefer the values in numerical order, be them flags or not.

share|improve this answer
1  
Sorting also reduces the probability of a bug slipping in, should someone start adding values to an enum. –  Leonid Feb 26 '13 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.