I have the following code in a User Control:
public partial class MyControl : System.Web.UI.UserControl
{
public Enums.InformationSubCategory SubCategory { get; set; }
...omitted code
}
Enums.InformationSubCategory is an enum I have defined elsewhere, with the idea being that I can do this:
Example 1. <my:MyControl runat="server" SubCategory="Food" ...... />
Example 2. <my:MyControl runat="server" ...... />
If I don’t specify a value at all for SubCategory, what will the value of SubCategory be in the code-behind for MyControl? Is it null or does a default value get applied to it? I noticed that with int properties, it defaults to zero.
Fields get initialized to
default(T). The easy way to remember what the default value of some type is that it corresponds to binary zero in the obvious implementation.For an enum this means that the underlying integer type is set to 0. By default this corresponds to the first value defined in the enum.
That’s why it’s common to name the first value in an enum
None.