[Mono-list] Parametized generics puzzler

Chris Howie cdhowie at gmail.com
Mon Feb 23 03:58:32 EST 2009


On Wed, Jan 28, 2009 at 7:40 AM, ebichete <ebichete at yahoo.com> wrote:
> Does anyone know why the following code doesn't "do the expected thing" ? I
> think I've properly coded my intent in C# but I could be wrong.
>
> I'm trying to get the base class static methods to act differently based on
> static data in the derived classes.
>
> [snip]

The problem here is that you are declaring new members with the same
name on the derived type Truck and are not actually overriding them.
This distinction is important.  Further, static members cannot be
overridden -- period.  What you want is something like:

public class Vehicle {
    public virtual string REG_TYPE { get { return ""; } }
    public virtual string TAX_CAT { get { return ""; } }
}

public class Truck : Vehicle {
    public override string REG_TYPE { get { return "G"; } }
    public override string TAX_CAT { get { return "J4"; } }
}

No generics or obnoxious getter methods needed.

P.S. Names like REG_TYPE are in bad taste.  Try something like RegistrationType.

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Mono-list mailing list