views:

13

answers:

0

I have experienced some unexpected behaviour in Visual Studio 2008 when I do the following.

In a base class (for example called A), I create a property called MyProperty that holds an int. I declare this property as virtual with public get and set methods.

Then I create a class B that inhetits from A, and here I override just the setter and don't mention the getter.

In the code I write something like this:

B myInstance = new B();
myInstance.MyProperty = 6;
int myInt = myInstance.MyProperty;

Now, I put a breakpoint on the last line here, and when I go into debug mode, I hover over MyProperty. The DataTip fails to display the value of MyProperty.

If I in addition override the getter in B like this:

get{
  return base.MyProperty
}

Then it works as expected. Therefore I have the following three questions:

  1. are there any reason why the DataTip won't display this value, or that it shoudn't?
  2. are there any workaround short of overriding the getter whenever I override the setter?
  3. are there any performance penalty of overriding the getter? Also, will if cause a extra method call since it has to go through B's get method, and not directly to A's get method.

Thanks in advance.