G
Guest
Just want to see if this is 'by design' or a bug...
I have a common List<T> defined in a base class, and the base class has a
static property to expose this list.
I wanted the derived class to add items to this list, but have the base
class hold the data and expose the property.
Problem is, however, that the derived class' static constructor doesn't get
called when DerivedClass.MyList is accessed, so the list has no members. If
I move the MyList property up to DerivedClass, it works as expected and
DerivedClass' static constructor is invoked.
I can understand why the BaseClass static constructor is called, but it
would also seem to make sense that DerivedClass' static constructor would be
called when an inherited static member is accessed/invoked..
Thoughts?
Thanks,
Kirk
public class DerivedClass : BaseClass
{
static DerivedClass
{
_list.Add("Foo");
}
[...]
}
public class BaseClass
{
protected static List<string> _list = new List<string>();
public static List<string> MyList
{
return _list;
}
static BaseClass()
{
}
[...]
}
I have a common List<T> defined in a base class, and the base class has a
static property to expose this list.
I wanted the derived class to add items to this list, but have the base
class hold the data and expose the property.
Problem is, however, that the derived class' static constructor doesn't get
called when DerivedClass.MyList is accessed, so the list has no members. If
I move the MyList property up to DerivedClass, it works as expected and
DerivedClass' static constructor is invoked.
I can understand why the BaseClass static constructor is called, but it
would also seem to make sense that DerivedClass' static constructor would be
called when an inherited static member is accessed/invoked..
Thoughts?
Thanks,
Kirk
public class DerivedClass : BaseClass
{
static DerivedClass
{
_list.Add("Foo");
}
[...]
}
public class BaseClass
{
protected static List<string> _list = new List<string>();
public static List<string> MyList
{
return _list;
}
static BaseClass()
{
}
[...]
}