Feel free to download the tiny project for the sample...
Introduction
Before all, this is my very first contribution (and it is NOT a classic application!) and I want to take advantage to thanks many of you that are helping so much the development. I will try hard to write down something useful in the near future, but at the moment I only drop this issue...
Today I have found a dirty bug in the Visual Studio 2008 Sp1 IDE or, at least, in the Visual C# Express since I am using it.
Using the code
The problem itself is tricky, because the (really useful) Intellisense tip showing the value of the variables, just fail on a simple inheritance case.
As you may see on the picture, there are two classes: let B inherited by C.
Now let assuming both B and C have the same property (signature), however with different access modifiers: let the base's property be marked as "virtual" and the derived's one marked as "override".
The "entire" program for test is just below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
C c = new C();
Console.WriteLine(c.Exec());
Console.ReadKey();
}
}
class B
{
public virtual int Value
{
get { return 10; }
}
}
class C : B
{
public override int Value
{
get { return 5; }
}
public int Exec()
{
return base.Value;
}
}
}
If you try to run the program, it outputs correctly "10" in the console window...but, what if you try to walk the code and stop just over the line marked with a remark?
Note: place a breakpoint here:
...
public int Exec()
{
return base.Value;
}
...
Here is a simple snapshot of the behavior:
Trick!...the tip shows "5" not "10", as I were typed as:
...
public int Exec()
{
return this.Value;
}
...
Points of Interest
I am assuming that Visual C# Express has the same "engine" of the bigger brother Visual Studio. I was not able to try this snippet inside the "real" Visual Studio Pro or superior. Please, feel free to feedback any different behavior.
History
First release.
Played with transistors and ICs before being ten. First approaches to programming (PET Commodore) in the early '80.
Then AppleSoft, TurboPascal, Assembler and VisualBasic.
Currently employed at CET Electronics as lead software developer, involved in creation of industrial control systems.
Loving graphics technologies, I had some great time with SVG.
Since 2006 my primary language is C#, where I am focusing on WPF.