Wednesday 5 February 2014

Gem #1: Parsing Enums

I came across this little line today which I didn't know of before or had forgotten, it's pretty neat so I wanted to start capturing these little gems as I come across them so I have a reference for myself:

Waveform waveform = 
(Waveform)Enum.Parse(typeof(Waveform), radio.Tag as string, true);

What this does is it takes a string in (in this case radio.Tag) and converts it to an Enum. Great for GUI code.

References / Follow-up:

No comments:

Post a Comment