C# Enum Parse via /r/learnprogramming


C# Enum Parse

using System; [Flags] enum Colors { None=0, Red = 1, Green = 2, Blue = 4 }; public class Example { public static void Main() { string[] colorStrings = { "0", "2", "8", "blue", "Blue", "Yellow", "Red, Green" }; foreach (string colorString in colorStrings) { try { Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString); if (Enum.IsDefined(typeof(Colors), colorValue)|colorValue.ToString().Contains(",")) Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString()); else Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString); } catch (ArgumentException) { Console.WriteLine("'{0}' is not a member of the Colors enumeration.", colorString); } } } } 

this is the full code, help me understand

 Colors colorValue = (Colors) Enum.Parse(typeof(Colors), colorString); if (Enum.IsDefined(typeof(Colors), colorValue)|colorValue.ToString().Contains(",")) 

this part? what is happening at this line?

Submitted July 18, 2017 at 01:55AM by Infinismegalis
via reddit http://ift.tt/2tlhIW8

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s