Back to Blog
C#

C# Enum Default Value: What default(MyEnum) Returns

c# enum default value: Learn what default(MyEnum) returns in C#, why the enum default value is always 0, and how to handle enums without a zero member.

C#EnumsDefault Values.NETValue Types
Editorial illustration showing a C# enum default value of zero with the zero member highlighted in a grid.

c# enum default value requires a clear understanding of the core syntax, runtime behavior, and practical implementation patterns demonstrated in the examples below.

When you write default(MyEnum) in C#, the result is always the enum member whose underlying value is zero, whether or not such a member exists. This behavior follows directly from how the runtime initializes value types, and it has practical consequences for fields, arrays, collections, and deserialization.

Why the Default Value Is Always Zero

Every enum in C# has an underlying integral type, usually int. The runtime treats an enum as a value type whose storage is that underlying integer. When a value type is default-initialized, its memory is zeroed out. For an enum, that means the underlying integer is 0, so default(MyEnum) produces the member with underlying value 0.

public enum Priority { Low = 1, Medium = 2, High = 3 } Priority p = default; // underlying value is 0, not Low

The variable p holds the integer 0, which does not correspond to any declared member of Priority. The code still compiles and runs; the runtime does not validate that an enum value matches a declared member.

When No Member Has the Value Zero

It is common to see enums where members start at 1:

public enum Status { Pending = 1, Active = 2, Closed = 3 }

A default(Status) field now holds 0, which is not a named member. Code that switches over the enum and assumes every value is a declared member will silently fall through. This is a frequent source of bugs in serialization, database mapping, and message queues, where a missing value can arrive as 0.

The safe convention is to declare an explicit member for 0, usually named None or Unknown:

public enum Status { None = 0, Pending = 1, Active = 2, Closed = 3 }

With this declaration, default(Status) is Status.None, and the default state is a meaningful, named value.

How Default Initialization Reaches Enums

Default initialization happens in more places than the default keyword. An uninitialized field of an enum type, an array of enums, and a List<T> that has just been created all contain the zero value:

public class Order { public Status Status; // default(Status) == Status.None } var statuses = new Status[10]; // every element is Status.None

The same applies to properties that are never set, dictionary values that are missing, and struct fields. Any code that reads an enum without explicit assignment is reading the zero value. If the enum has no zero member, that read produces an unnamed value.

The DefaultValue Attribute Does Not Change Runtime Behavior

The [DefaultValue] attribute is metadata for designers and serializers. It does not change what default(MyEnum) returns:

public class Config { [DefaultValue(Status.Active)] public Status Status { get; set; } }

A new Config instance still has Status == Status.None (or the unnamed zero value) until the property is assigned. The attribute only informs tools that read metadata, such as the Windows Forms designer or certain serializers. Relying on it to initialize a property will produce unexpected results.

Nullable Enums Default to Null

Declaring the enum as nullable changes the default:

public Status? Status { get; set; } // default is null

A nullable enum wraps the underlying value in Nullable<T>. The default of a nullable value type is null, not the zero enum member. This is useful when the absence of a value is semantically different from a value of None. The cost is a small allocation-free wrapper and the need to check HasValue before reading the enum.

Flags Enums and the Zero Member

For a [Flags] enum, zero means no flags are set:

[Flags] public enum Permissions { None = 0, Read = 1, Write = 2, Execute = 4 }

default(Permissions) is Permissions.None, which is also the result of combining no bits. The zero member is required for the flags pattern to behave predictably in bitwise operations and in Enum.HasFlag. Without a zero member, a default-initialized flags enum holds an unnamed value that fails HasFlag checks for every declared flag.

Parsing and Validation of the Zero Value

Enum.Parse and Enum.TryParse accept numeric strings, so "0" parses successfully even when no member is declared at zero:

bool ok = Enum.TryParse<Status>("0", out Status value); // ok is true, value is the unnamed zero value

Validation that checks Enum.IsDefined will reject the unnamed zero value:

if (!Enum.IsDefined(typeof(Status), value)) { // value is not a declared member }

This is the correct guard when an enum arrives from external input such as JSON, a database, or a request body. It prevents an unnamed zero from flowing into business logic that expects only declared members.

Choosing a Strategy for the Zero Member

The decision to declare a zero member depends on the domain. For enums that represent states, options, or categories, an explicit None or Unknown member makes the default state visible and testable. For enums where every value must be explicitly assigned, leaving zero undeclared forces callers to notice the gap, but it also makes default-initialized instances hold an invalid value.

A pragmatic rule: if the enum is stored, serialized, or read from external input, declare a zero member and validate with Enum.IsDefined. If the enum is purely internal and always assigned before use, the unnamed zero value is less dangerous but still worth handling in any switch that has a default branch.

c# enum default value: Practical Usage and Code Examples | RYUSLOG DEV