I have a Windows Application that is accepting a string via command line parameter.
The string is going to be one of the following: 19, 20, 21, 23, 25. This is an ID that is used to build a URL dynamically.
I’ve used enums in plenty of apps before, but I’ve never actually built an enum from scratch so (I feel foolish saying this), I don’t entirely understand them.
Based on the string that’s passed in, I want to set a UI label. The corresponding values I want to display are as follows (recall the # value is the string that’s passed in):
19 = Facebook
20 = Twitter
21 = YouTube
23 = Flickr
25 = Blogs
So if 23 is passed in, my label would say “Flickr”. Is this something I can do with enums?
public Form1(string collectorID)
{
InitializeComponent();
this.CollectorID = collectorID;
labelCollector.Text = // Set label here
WebConnection.Create(CollectorID);
}
Thanks!
Scott
Be aware that many programmers (including me) consider using the
ToString()of an enum a little “foolish” (this because you are making everything “immutable unless you modify the program” and “unlocalizable”)I’ll add that you could do it with a
Dictionary(a little better, the Dictionary could be loaded dynamically):