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 9148751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:21:34+00:00 2026-06-17T11:21:34+00:00

There are this , this and this questions about Enum VS Property name conflicts.

  • 0

There are this, this and this questions about Enum VS Property name conflicts.

My question is not about the naming conventions, instead I’d like to know how to solve the name conflict demonstrated in the code below:

namespace Test
{
    public class Person
    {
        // 1)
        // Gender? Gender { get; set; }

        // 2)
        Gender Gender { get; set; }

        public Person ()
        {
            // 1 - Error CS1061: Type `Test.Gender?' does not contain a definition for `Male' and no extension method `Male' of type `Test.Gender?' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Test)
            // 2 - OK
            Gender = Gender.Male;
        }
    }

    public enum Gender
    {
        Male = 1,
        Female
    }
}

If I declare the property as in 2) Gender Gender { get; set; } the code compiles successfully, however, if I declare as in 1) Gender? Gender { get; set; } (commented in the code above) i get the error

Error CS1061: Type `Test.Gender?' does not contain a definition for `Male' and no extension method `Male' of type `Test.Gender?' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Test)

Why does it happen ?

  • 1 1 Answer
  • 0 Views
  • 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-06-17T11:21:35+00:00Added an answer on June 17, 2026 at 11:21 am

    Gender? means Nullable<Gender>, this means that when you write Gender.Male the compiler thinks you are trying to invoke a getter on a property called Male on the Nullable<Gender> instance, i.e. Gender is interpretted as a read of the this.Gender property and Male as the read of a property called Male upon the result of that.

    The compiler does not identify case (2) as an error as enums cannot have methods so the only resolution that makes sense is for the symbol is the enum itself.

    You can fix this by increasing the name qualification:

    namespace Acme.Fruits.Banana
    {
        ...
        public Person()
        {
            Gender = Banana.Gender.Male
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I know there are a lot of questions about this and a lot
I know that there are many different questions about this sort of topic on
I know there's a lot of questions about this but I've been struggling with
ok, I know there are a lot of questions here about this, that are
I know there are dozens of questions on different sites about this issue. I
I know there's a couple of questions about this out there but I still
There are several other questions about this topic that I have gone through, but
There seem to be many questions asked about this subject here on stackoverflow, but
There are two questions to this: How can I best spread the word about
There are nice SO question and answers about this issue, but these options didn't

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.