Enum parsing from strings
📖 Scenario: You are building a simple program that reads color names as text and converts them into color codes using an enum.
🎯 Goal: Create an enum called Color with specific colors, then write code to convert a string into the matching Color enum value.
📋 What You'll Learn
Create an enum named
Color with values Red, Green, and BlueCreate a string variable named
inputColor with the value "Green"Parse the string
inputColor into a Color enum variable named parsedColorPrint the
parsedColor variable to the console💡 Why This Matters
🌍 Real World
Enums are used to represent fixed sets of related values, like days of the week, colors, or states. Parsing strings to enums helps convert user input or data into these fixed categories.
💼 Career
Understanding enums and parsing is important for building clear, maintainable code in many C# applications, including games, business software, and web services.
Progress0 / 4 steps