P
Pavils Jurjans
Hello,
Please see the following code:
using System;
public class Parent
{
public virtual string id = "_";
public string getId()
{
return id;
}
}
public class Child : Parent
{
public override string id = "A";
}
public class Executer
{
public static void Main()
{
Parent p = new Child();
Console.Write(p.getId());
}
}
Of course, this doesn't compile. But, is there some way to override parent
class field values with child ones, just like it is possible with
virtual/override on methods? Currently I see that I can create a "getId"
method for every child class, but that seems to be quite clumsy method.
Thanks,
-- Pavils
Please see the following code:
using System;
public class Parent
{
public virtual string id = "_";
public string getId()
{
return id;
}
}
public class Child : Parent
{
public override string id = "A";
}
public class Executer
{
public static void Main()
{
Parent p = new Child();
Console.Write(p.getId());
}
}
Of course, this doesn't compile. But, is there some way to override parent
class field values with child ones, just like it is possible with
virtual/override on methods? Currently I see that I can create a "getId"
method for every child class, but that seems to be quite clumsy method.
Thanks,
-- Pavils