[antlr-interest] In c#, how to override a vaiable in a subclass
Micheal J
open.zone at virgin.net
Tue Mar 28 03:00:16 PST 2006
> I want to declare a geneirc variable in a parent class, then
> use it as as diffrent type in respective subclasses. I tried
> as such which was rejected:
>
> class P
> {
> object v;
> ...
> }
You can't "override" a field. What about using properties?
Given class P as above (v needs to be declared as "protected"), you could
try this:
class Child1 : P
{
public int Value
{
get { return (int)v; }
set { v = value; }
}
}
class Child2 : P
{
public string Value
{
get { return (string)v; }
set { v = value; }
}
}
Cheers,
Micheal
More information about the antlr-interest
mailing list