Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
AnswerRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Gerry Schmitz31-Jul-23 16:50
mveGerry Schmitz31-Jul-23 16:50 
SuggestionRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Richard Deeming31-Jul-23 22:04
mveRichard Deeming31-Jul-23 22:04 
GeneralRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Paulo Zemek1-Aug-23 1:25
mvaPaulo Zemek1-Aug-23 1:25 
GeneralRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Paulo Zemek1-Aug-23 1:46
mvaPaulo Zemek1-Aug-23 1:46 
GeneralRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Richard Deeming1-Aug-23 1:50
mveRichard Deeming1-Aug-23 1:50 
GeneralRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Paulo Zemek1-Aug-23 11:35
mvaPaulo Zemek1-Aug-23 11:35 
AnswerRe: Should we ever create enums? (C#, maybe valid for C++) Pin
BillWoodruff1-Aug-23 2:15
professionalBillWoodruff1-Aug-23 2:15 
AnswerRe: Should we ever create enums? (C#, maybe valid for C++) Pin
trønderen1-Aug-23 12:37
trønderen1-Aug-23 12:37 
Skipping the class/struct/readonly/whatever discussions, and commenting on the subject line topic: Enums.

My programming childhood (i.e. as a university freshman) was with Pascal, which provided true enums. Not named integers. In the C language class, replacing integer #define with enum is just syntactical sugar. They are integers in disguise. Or not really disguise - it is just a very thin veil.

The very idea behind enums is that they are not integers, no matter what C programmers say. January, February and so on are months, not integers! May is May. It takes a C programmer to get into an argument whether the month of May "really" is 4 or 5. Well, the C programmer would never be in doubt. Also, half of May is March, that is obvious, isn't it? (Half of June is also March.)

Noooo! Enums are countable (enumerable, if you prefer). So are apples. That doesn't make an apple an integer.

If you are really talking about integers, they are integers. Replacing the digit 0 with 'D0', 1 with 'D1' and so on does not, not in any way whatsoever, 'improve legibility'. Quite to the contrary; it hides the fact that you are in fact talking about integer numbers. The reader has to look up the definition of 'D4' to see what it represents: Is it the binary integer 4, or is is the character code for the '4' digit character, or something quite different, such as 'dictionary entry with key 4'?

Enums have no place in this context of yours - not even in the C-style 'enums are named integers' style. You are handling true integers. Declare them as true integers, and nothing else.

(And: If Pascal had still been alive, you could have had exactly what you are trying to achieve defining new subrange type such as TYPE SingleDigitInteger = 0 ..9; and the compiler + runtime system would catch all attempts to set a variable/field of this type to a value outside its defined range. It would still be a numeric integer. Unfortunately, Pascal, and a lot of great ideas it represented, died several decades ago.)
GeneralRe: Should we ever create enums? (C#, maybe valid for C++) Pin
Paulo Zemek1-Aug-23 15:14
mvaPaulo Zemek1-Aug-23 15:14 
GeneralRe: Should we ever create enums? (C#, maybe valid for C++) Pin
harold aptroot2-Aug-23 6:37
harold aptroot2-Aug-23 6:37 
QuestionNew Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
pr1mem0ver29-Jul-23 20:23
pr1mem0ver29-Jul-23 20:23 
AnswerRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
Pete O'Hanlon29-Jul-23 23:28
mvePete O'Hanlon29-Jul-23 23:28 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
pr1mem0ver30-Jul-23 10:44
pr1mem0ver30-Jul-23 10:44 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
Pete O'Hanlon30-Jul-23 20:23
mvePete O'Hanlon30-Jul-23 20:23 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
BillWoodruff31-Jul-23 3:26
professionalBillWoodruff31-Jul-23 3:26 
AnswerRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
BillWoodruff30-Jul-23 1:22
professionalBillWoodruff30-Jul-23 1:22 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
OriginalGriff30-Jul-23 2:35
mveOriginalGriff30-Jul-23 2:35 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
BillWoodruff30-Jul-23 3:54
professionalBillWoodruff30-Jul-23 3:54 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
pr1mem0ver30-Jul-23 11:13
pr1mem0ver30-Jul-23 11:13 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
BillWoodruff30-Jul-23 14:30
professionalBillWoodruff30-Jul-23 14:30 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
pr1mem0ver30-Jul-23 15:33
pr1mem0ver30-Jul-23 15:33 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
Pete O'Hanlon30-Jul-23 3:19
mvePete O'Hanlon30-Jul-23 3:19 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
pr1mem0ver30-Jul-23 18:35
pr1mem0ver30-Jul-23 18:35 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
pr1mem0ver30-Jul-23 11:13
pr1mem0ver30-Jul-23 11:13 
GeneralRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
Dave Kreskowiak30-Jul-23 13:07
mveDave Kreskowiak30-Jul-23 13:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.