Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
AnswerRe: doubt Pin
Patrice T18-Apr-16 5:38
mvePatrice T18-Apr-16 5:38 
QuestionRoslyn compiler Pin
V.18-Apr-16 2:27
professionalV.18-Apr-16 2:27 
AnswerRe: Roslyn compiler Pin
Richard Deeming18-Apr-16 2:42
mveRichard Deeming18-Apr-16 2:42 
QuestionInsert rows c# Pin
Bougarra17-Apr-16 23:11
Bougarra17-Apr-16 23:11 
AnswerRe: Insert rows c# Pin
Pete O'Hanlon17-Apr-16 23:55
mvePete O'Hanlon17-Apr-16 23:55 
QuestionForm disappearing Pin
Member 238990017-Apr-16 0:02
Member 238990017-Apr-16 0:02 
AnswerRe: Form disappearing Pin
OriginalGriff17-Apr-16 0:36
mveOriginalGriff17-Apr-16 0:36 
GeneralRe: Form disappearing Pin
Member 238990017-Apr-16 0:46
Member 238990017-Apr-16 0:46 
GeneralRe: Form disappearing Pin
OriginalGriff17-Apr-16 0:50
mveOriginalGriff17-Apr-16 0:50 
GeneralRe: Form disappearing Pin
Member 238990017-Apr-16 0:55
Member 238990017-Apr-16 0:55 
GeneralRe: Form disappearing Pin
OriginalGriff17-Apr-16 1:06
mveOriginalGriff17-Apr-16 1:06 
GeneralRe: Form disappearing Pin
Member 238990017-Apr-16 1:16
Member 238990017-Apr-16 1:16 
GeneralRe: Form disappearing Pin
OriginalGriff17-Apr-16 1:30
mveOriginalGriff17-Apr-16 1:30 
GeneralRe: Form disappearing Pin
Member 238990017-Apr-16 1:42
Member 238990017-Apr-16 1:42 
GeneralRe: Form disappearing Pin
OriginalGriff17-Apr-16 1:44
mveOriginalGriff17-Apr-16 1:44 
GeneralRe: Form disappearing Pin
OriginalGriff17-Apr-16 1:40
mveOriginalGriff17-Apr-16 1:40 
GeneralRe: Form disappearing Pin
Philippe Mori18-Apr-16 12:34
Philippe Mori18-Apr-16 12:34 
AnswerRe: Form disappearing Pin
ChizI19-Apr-16 7:25
ChizI19-Apr-16 7:25 
Questionusing Enums as a design-strategy ? Pin
BillWoodruff16-Apr-16 21:59
professionalBillWoodruff16-Apr-16 21:59 
AnswerRe: using Enums as a design-strategy ? Pin
Garth J Lancaster16-Apr-16 23:01
professionalGarth J Lancaster16-Apr-16 23:01 
GeneralRe: using Enums as a design-strategy ? Pin
BillWoodruff16-Apr-16 23:29
professionalBillWoodruff16-Apr-16 23:29 
AnswerRe: using Enums as a design-strategy ? Pin
John Torjo18-Apr-16 1:37
professionalJohn Torjo18-Apr-16 1:37 
A few notes on my opinions/usages on enums:

1. I quite love enums. Especially when you use them to specify an argument to a function

Like enforcing a constraint,

enum month { jan, feb, ... , dec };

2. I know there are pitfalls, but if you know them, enums are really powerful. They are self-documenting. Code looks much better at the point of call.

Just imagine:

var lines = x.Split( new[] {"\r\n"}, SplitOptions.RemoveEmptyEntries);

The latter argument could have been a boolean, but then the code would have been much harder to understand:

<br />
// what does "true" really mean?<br />
var lines = x.Split( new[] {"\r\n"}, true);


3. One of the possible problems when using enums is when you add a new value. In this case, you'll pretty much need to update all the code that used switch-es based on this enum. That's why I strive to have as few functions that require a switch based on all possible values.

4. About "future fragility": If other code depends on exact enum values, I usually put a comment on top of the enum

// Do not change the values. Other assemblies depend on this exact matching<br />
enum month { jan = 1, feb = 2, ... , dec = 12 };


5. "Nested" enums. I have used something more or less similar in my code, but never more than 2 levels deep. So far, I haven't encountered any pitfalls.

6. Took a look at the Class based alternative - clearly, there are some scenarios for it, but I think most of the time, it's overkill (my personal opinion, of course Wink | ;) )

Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!

GeneralRe: using Enums as a design-strategy ? Pin
BillWoodruff18-Apr-16 4:45
professionalBillWoodruff18-Apr-16 4:45 
GeneralRe: using Enums as a design-strategy ? Pin
John Torjo18-Apr-16 9:12
professionalJohn Torjo18-Apr-16 9:12 
QuestionHow do i establish a ADO.NET application without installing SqlServer in client side. Pin
Member 1246281515-Apr-16 20:44
Member 1246281515-Apr-16 20:44 

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.