Let's say I have:
public class Fruit
{
public static List<String> Suppliers { get; protected set; }
static Fruit()
{
Suppliers = new List<String>();
Suppliers.Add("Company A");
}
}
public class Banana : Fruit
{
static Banana()
{
Suppliers.Add("Company B");
}
}
If I just do this in the calling code:
foreach(String supplier in Banana.Suppliers)
Console.WriteLine(supplier);
I get:
- Company A
Whereas if I do:
Banana b = new Banana();
foreach(String supplier in Banana.Suppliers)
Console.WriteLine(supplier);
I get (the desired result):
- Company A
- Company B
Edit: After reading the responses I understand that this won't work.
What I want in my production code is a list of values that is common to the type of object and I want to dynamically add different values to that list of strings based on the subtype. (The context is LDAP - all entries have objectClass=top and all user-objects have objectClass=user,top,organizationPerson,person). Guess I have to use an interface or different lists in each subclass or something if no one has a better suggestion?