Enum has a default value!! (C# Reference)

Edit
While I was writing a unit test for null value test, I found my code didn't throw except as I planned. After some investigations I have come to a big discover. All enum class in C# will be assign the "0" index enum type as it's default value!! The exact wording from msdn is

The default value of an enum E is the value produced by the expression (E)0.

Which means I can remove all the check null code for enum!

Reference: enum (C# Reference)

Enum has a default value!! (C# Reference) Enum has a default value!! (C# Reference) Reviewed by DF on 11:15:00 PM Rating: 5
©DF. Powered by Blogger.