KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've spent a while trying to understand why my WPF app wasn't databinding to an enum property propertly and this is the cause. static void Main(string[] args) { MyEnum x = 0; Console.WriteLine(x.ToString()); Console.ReadLine(); } public enum MyEnum { First = 1, Second = 2 } Essentially the problem was that there was no default value set for the enum property in the constructor of the class I was binding to, so it was defaulting to zero. Is there someway I can tell the C# compiler that I want it to only accept valid values (and default to the lowest value)? I don't want my property to accept invalid values, and I don't want to have to write setter code for every property that uses an enum.
Tags (comma-separated)
Save Edits
Cancel