Hi,
I have a class hierarchy, and would like all classes in
the tree to have a common, static readonly variable -
with a class-specific value. I'd like it to be readonly
(it should never change), but this prevents me from
setting its value in the static constructor of the
subclasses - I'm allowed to set its value in the
superclass constructor only.
Any suggestions as to what would be a good solution?
An example is provided below:
public class A
{
public static readonly string MyString;
static A
{
MyString = "Hello, World!"; // This is OK.
}
}
public class B : A
{
static B
{
MyString = "Bonjour, Le Monde!"; // This is NOT.
}
}