How to convert an enum to a List in C#?
Hello everyone! I'm a beginner C# developer and I have a problem with enums. I have this enum:\n\n```csharp\npublic enum Colors\n{\n Red,\n Green,\n Blue,\n Yellow\n}\n```\n\nI need to get a list of all values of this enum as `List` so that I can, for example, populate a ComboBox or simply iterate through all options in a loop. I tried something like `Colors.ToList()`, but the compiler gives an error. I also tried `Enum.GetValues(typeof(Colors))`, but it returns an array, not a list. I specifically need `List`.\n\nPlease advise how to correctly convert an enum to a list? And is it possible to immediately get a list of string representations (e.g., "Red", "Green")? I would be grateful for a simple and clear example.
No answers yet.
Log in to leave an answer