Could someone give me some very basic examples and some explanations of what enums do?
I'm following a tutorial but it's not really explained them before use, and the MSDN page is a little over complexing it.
1 reply to this topic
#1
Posted 29 November 2010 - 08:37 AM
|
|
|
#2
Posted 29 November 2010 - 10:08 AM
It is a way to store multiple items in sequential order, each with its own numeric index. An example:
Enums and Structs in C# - CodeProject
enum Rating {Poor, Average, Okay, Good, Excellent}
Rating IncrementRating(Rating r)
{
if(r == Rating.Excellent)
return r;
else
return r+1;
}
Rating DecrementRating(Rating r)
{
if(r == Rating.Poor)
return r;
else
return r-1;
}As you can see there is a good use in this, for example defining error codes or messages, as you can compare them as integers by name. Some more examples can be found here:Enums and Structs in C# - CodeProject
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









