Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please give me answer for this question.
Posted
Comments
CPallini 17-Feb-11 9:31am    
I give you an answer about their limitations: they cannot replace Google, for instance...

This [^]is what MSDN says about enum is c#.

When to use Enumerations[^]

According to this article:
'The benefits of using enumerations include:

Reduces errors caused by transposing or mistyping numbers.

Makes it easy to change values in the future.

Makes code easier to read, which means it is less likely that errors will creep into it.

Ensures forward compatibility. With enumerations, your code is less likely to fail if in the future someone changes the values corresponding to the member names.'
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 17-Feb-11 18:26pm    
Always good to refer to MSDN (why OP does do it?), my 5.
Did you see my Article "Enumeration Types do not Enumerate! Working around .NET and Language Limitations" (see my answer)? Maybe not quite to OP level, but you may find it just intriguing.
--SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Feb-11 18:25pm    
Not bad, my 5.
The article is good "slow" introduction, only Trick section does not protect against some common fallacies, but I do it in my article. Would you like to look at my Answer?
--SA
Please forgive me if my Answer is a bit off-topic and many a bit too advanced to you. I still think it could be very useful.

I want to reference my CodeProject article which shows some good and simple enumeration techniques many developers do not know. But more intriguing is the main topic. I may come as surprise, but C# (as well as C/C++) enumeration types are not "real" enumeration types as in some other languages!

The reason is very convincing: they do not enumerate! In .NET terms it means they do not implement the interface IEnumerable needed to enumerate using foraech. Note that some other languages do it inherently.

The article overview the ways to work around, but the main result is the enumerator build around any existing type. Also, it protects from some common fallacies related to main topic.

Please see: Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^].

Good luck,
—SA
 
Share this answer
 
Try this nearly 10 year old article I wrote on the topic:

Enums and Structs in C#[^]

Also see http://msdn.microsoft.com/en-us/library/sbbt4032(v=VS.100).aspx[^]

One of the most common uses is to avoid magic numbers and instead to use a typesafe readable name that identifies a value.
 
Share this answer
 
v3
Comments
Manas Bhardwaj 17-Feb-11 9:39am    
+10 : 5 for answer + 5 for your article :)
Nish Nishant 17-Feb-11 9:44am    
Thank you :-)
Sergey Alexandrovich Kryukov 17-Feb-11 18:23pm    
Pretty good introductory material. I voted 5 for Answer and the article.
Did you see my Article "Enumeration Types do not Enumerate! Working around .NET and Language Limitations" (see my answer)? Maybe not quite to OP level, but you may find it just intriguing.
--SA
Nish Nishant 17-Feb-11 19:21pm    
Thanks SA, yes I've seen it before but have not got a chance to read it in full. I will do so at some time :-)
Sergey Alexandrovich Kryukov 17-Feb-11 19:46pm    
Thank you, this is a series of 3 works; next one is on human-readable presentation (UI) and localization, last on on Enumeration-based command line; last one is most popular, first one I think most interesting.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900