G
Guest
It looks like the language is trying to prevent me from doing this sort of
thing. Nevertheless, the following compiles, and I'd like to know why it
doesn't work the way it should:
public class ComponentA
{
static string s_name = "I am the root class.";
public string Name { get {return s_name;} }
}
public class ComponentB : ComponentA
{
new static string s_name = "I am a derived class.";
}
static void Main()
{
ComponentB b = new ComponentB();
Console.WriteLine("ComponentB says: " + b.Name);
}
I want this to say "I am a derived class." but it still says "I am the root
class."
My objective is to derive a whole bunch of classes on which I can get a
description both
- Through reflection of the class Type (thus requiring the static member)
- Through an instance of the class using a (virtual) member that is defined
in the root class.
Is this possible?
thing. Nevertheless, the following compiles, and I'd like to know why it
doesn't work the way it should:
public class ComponentA
{
static string s_name = "I am the root class.";
public string Name { get {return s_name;} }
}
public class ComponentB : ComponentA
{
new static string s_name = "I am a derived class.";
}
static void Main()
{
ComponentB b = new ComponentB();
Console.WriteLine("ComponentB says: " + b.Name);
}
I want this to say "I am a derived class." but it still says "I am the root
class."
My objective is to derive a whole bunch of classes on which I can get a
description both
- Through reflection of the class Type (thus requiring the static member)
- Through an instance of the class using a (virtual) member that is defined
in the root class.
Is this possible?