Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1005273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:16:06+00:00 2026-05-16T08:16:06+00:00

Consider the following Enum and a corrsponding nullable field of that type enum PossibleOptions

  • 0

Consider the following Enum and a corrsponding nullable field of that type

enum PossibleOptions { One, Two }

PossibleOptions? option;

Alternatively I could declare the enum and the corresponding field as

enum PossibleOptions { Unspecified, One, Two }

PossibleOptions option;

This non-nullable field would be initialized to the first value i.e ‘Unspecified’ and I achieve the same result as a nullable (‘Unspecified’ would replace option.HasValue).

Why go for a Nullable then? Any performance gains or other advantages?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:16:07+00:00Added an answer on May 16, 2026 at 8:16 am

    According to the documentation:

    The default underlying type of the
    enumeration elements is int. By
    default, the first enumerator has the
    value 0, and the value of each
    successive enumerator is increased by
    1.

    …

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

    There is also possibility to modify this default value:

    enum PossibleOptions { Unspecified = 1, One, Two }
    

    In this case Unspecified will no longer be the default value.

    The only possible advantage that I can see of using a nullable enum is that the null value will not be dependent on the definition of the enumeration.

    In my opinion you should decide which one to use depending on whether you need the semantics of default value or unassigned value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following two enums: enum MyEnum1 { Value1 = 1, Value2 = 2,
Please consider the following code. enum type {CONS, ATOM, FUNC, LAMBDA}; typedef struct{ enum
Consider following code: enum size = 16; double[size] arr1 = [...]; double[size] arr2 =
Let's consider the following enum in C# public enum ScrollMode : byte { None
Background Consider the following: template <unsigned N> struct Fibonacci { enum { value =
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following (simplified) code: enum eTestMode { TM_BASIC = 1, // 1 <<
Consider the following code: public enum SomeCode { NIF = 0 ,NIE = 1
Consider the following class: class Foo { enum Flags {Bar, Baz, Bax}; template<Flags, class
Consider the following method, public void Add(Enum key, object value); Since Enum is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.