Classes
public class Building
{
public string Name = "Not To Be Seen";
...
}
public class School: Building
{
public int NoOfRooms = 200;
public string Address = "123 Main St.";
...
}
Goal (n some other class / use case)
// This is a simple example, in reality this code is far more complex
// the class "School" is private from the program
List<Building> city = new List<School>();
// city will only have properties of the class School (or at least those are the only properties seen)
Console.WriteLine(city[0].NoOfRooms.ToString()) // Outputs 200
Console.WriteLine(city[0].Name) // Should not output anything
This seems like it should be very possible depending on correctly converting the lists. However, I cannot seem to figure out how to get this to work. It seems like it involves co-variance, but I do not want an immutable list or type. Doesn't C# offer this kind of conversion easily (i.e. base class can fully mimic a derived class)?
Thanks