Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Difference between enumerators and constants

Hello

What is the difference between enumerators and constants ? Constants seems to be more easier to use than enumerators, because in enumerators you have to cast to int to access the value which leads to more confusion.

I have seen many programs which uses enums than constants. Any specific reason why developers are more biased to enumerators ?
0
praveenuni
Asked:
praveenuni
  • 2
1 Solution
 
DarkoLordCommented:
Hi,

When using enums, you usually don't work with values directly. Usually you use them where there are multiple (but finite) number of possible choices. They are easier to work with, as when developing you can immediately see all possible options, so it's a lot less confusing.

Look at this picture, for example: http://www.braintique.com/csharp/figures/f0105.jpg 
How would you know which integer value is which icon in this case?

Also, enums can be bound to any databound control, so you can for example just bind the entire enum to a ComboBox instead of matching the value/name pairs manually.

Regards,
Darko
0
 
DarkoLordCommented:
0
 
praveenuniAuthor Commented:
Thanks DarkoLord.

0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now