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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:48:57+00:00 2026-05-14T02:48:57+00:00

I have a base class Parent like this: using System; using System.Collections.Generic; using System.Text;

  • 0

I have a base class “Parent” like this:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Parent
    {
        private int parentVirtualInt = -1;
        public virtual int VirtualProperty
        {
            get
            {
                return parentVirtualInt;
            }
            set
            {
                if(parentVirtualInt != value)
                {
                    parentVirtualInt = value;
                }
            }
        }
    }
}

and a child class like this:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Child : Parent
    {
        public override int VirtualProperty
        {
            get
            {
                if(base.VirtualProperty > 0)
                {
                    throw new ApplicationException("Dummy Ex");
                }
                return base.VirtualProperty;
            }
            set
            {
                if(base.VirtualProperty != value)
                {
                    base.VirtualProperty = value;
                }
            }
        }
    }
}

Note that the getter in Child is calling the getter of Parent (or at least this is what I intend).

I now use the “Child” class by instantiating it, assigning a value (let’s say 4) to its VirtualProperty and then reading the property again.

Child c = new Child();
c.VirtualProperty = 4;
Console.Out.WriteLine("Child.VirtualProperty: " + c.VirtualProperty);

When I run this, I obviously get an ApplicationException saying “Dummy Ex”. But if I set a breakpoint on the line

if(base.VirtualProperty > 0)

in Child and check the value of base.VirtualProperty (by hovering the mouse over it) before the exception can be thrown (I assume(d)), I already get the Exception. From this I convey that the statement base.VirtualProperty in the “Child-Getter calls itself”; kind of.

What I would like to achieve is the same behavior I get when I change the definition of parentVirutalInt (in Parent) to protected and use base.parentVirtualInt in the Getter of Child instead of base.VirtualProperty. And I don’t yet see why this is not working. Can anybody shed some light on this? I feel that overridden properties behave differently than overridden methods?

By the way: I am doing something very similar with subclassing a class I do not have any control over (this is the main reason why my “workaround” is not an option).

Kind regards

  • 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-14T02:48:57+00:00Added an answer on May 14, 2026 at 2:48 am

    It is (arguably) a bug in the debugger. You can add your vote to this feedback article. This isn’t easy to fix, I’m sure, the debugger doesn’t have ready access to the base property getter method address since the v-table slot for the property getter has been replaced in the derived class.

    One possible workaround is to store the base value in a local variable first so you can inspect that one. That isn’t going to make your getter any slower.

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

Sidebar

Related Questions

I have a base class that has a private static member: class Base {
I have a base class vehicle and some children classes like car, motorbike etc..
I have an abstract class BaseItem declared like this: public abstract class BaseItem {
I have a base class object array into which I have typecasted many different
I have a base class with an optional virtual function class Base { virtual
I have a base class that represents a database test in TestNG, and I
I have a base class with a property which (the get method) I want
I have a base class in which I want to specify the methods a
I have a base class with a virtual method, and multiple subclasses that override
I have a base class Node which contains a list of child nodes. Node

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.