How to set enum to null
Make your variable nullable. Like:
Color? color = null;
or
Nullable<Color> color = null;
You can either use the "?" operator for a nullable type.
public Color? myColor = null;
Or use the standard practice for enums that cannot be null by having the FIRST value in the enum (aka 0) be the default value. For example in a case of color None.
public Color myColor = Color.None;
If this is C#, it won't work: enums are value types, and can't be null
.
The normal options are to add a None
member:
public enum Color
{
None,
Red,
Green,
Yellow
}
Color color = Color.None;
...or to use Nullable
:
Color? color = null;