Selecting appropriate override
- From: "Réal Forté" <real.forte@xxxxxxxxxx>
- Date: Tue, 30 Aug 2005 14:09:08 -0400
Hi,
I have a puzzling case here:
using System;
namespace TestOverrides
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Ancestor dummy = new SubClass();
Container.Hello(dummy);
}
}
class Ancestor
{
public String Field1 = "Field1";
}
class SubClass : Ancestor
{
public int Field2 = 27;
}
class Container
{
public static void Hello(SubClass pParm)
{
Console.WriteLine(pParm.Field2);
}
public static void Hello(Ancestor pParm)
{
Console.WriteLine(pParm.Field1);
}
}
}
In this peice of code, I would have expected 27 to print, but it always
prints "Field1". It seems that it does not recognize that, although the
parameter is declared as «Ancestor», it really is of «SubClass» class. Any
suggestion here?
Thank you
Real
.
- Follow-Ups:
- Re: Selecting appropriate override
- From: Jon Skeet [C# MVP]
- Re: Selecting appropriate override
- From: Adam Clauss
- Re: Selecting appropriate override
- From: Marina
- Re: Selecting appropriate override
- Prev by Date: Re: Databound Item Replace
- Next by Date: Re: Selecting appropriate override
- Previous by thread: DLL vs Dynamic Compile
- Next by thread: Re: Selecting appropriate override
- Index(es):
Relevant Pages
|