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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:10:21+00:00 2026-05-27T15:10:21+00:00

I have a class that exposes an auto implemented property Enabled Public MustInherit Class

  • 0

I have a class that exposes an auto implemented property Enabled

Public MustInherit Class TopLevel
    Protected Property Enabled() As Boolean
End Class

In an inhertited class I cannot access _Enabled

Public Class SubClass
    Inherits TopLevel

    Public Function Foo() As string
        If Not _Enabled Then Return Nothing '<- This fails
    End SUb
End Class

But If I had not use an auto implemented property and declared my own backing-field as follows this is accessible from the subclass:

Private _Enabled as Boolean

—- EDIT —-
The abve line is incorrect – this is not possible, it was in fact Protected in the original code which allowed access from the sub class See @JonSkeet answer
—- EDIT —-

Of course I can just access Enabled from the sub class to work around this but can someone explain why this is the behaviour?

  • 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-05-27T15:10:21+00:00Added an answer on May 27, 2026 at 3:10 pm

    But If I had not use an auto implemented property and declared my own backing-field as follows this is accessible from the subclass:

    Private _Enabled as Boolean
    

    No it wouldn’t – private fields aren’t accessible from derived classes – only protected ones are. (The exception to this being nested classes, which have access to their containing class’s private members.)

    From the docs for the Private modifier:

    Specifies that one or more declared programming elements are accessible only from within their declaration context, including from within any contained types.

    Personally I’d regard it as bad form to access the backing field of an automatically implemented property directly anyway – in C#, it’s not even available, as it’s given an unspeakable name (one which isn’t valid in C# itself). If you want the value of the property from your derived class, why don’t you just access it as a property? That would be the appropriate approach even if you weren’t using automatically implemented properties – your fields should be private.

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

Sidebar

Related Questions

I have a class that defines a read-only property that effectively exposes a private
I have a List<T> where T is a class that exposes a Username property.
Assume that I have a class that exposes the following event: public event EventHandler
Let's say I have a class that exposes one property. Is it considered to
I have a .net assembly that exposes a public class (named A) to be
I have a data object -- a custom class called Notification -- that exposes
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a templated C++ class that exposes a number of methods, e.g template<int
I have a Delphi generic class that exposes a function with an argument of
I'm using a class library that exposes a few objects. These objects have 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.