Say I have 2 classes:
Class 1:
public class Class1
{
public static string Test = "Class1";
}
And Class 2:
public class Class2
{
public static string Test = "Class2";
}
Now in my mainform, I have an array of objects:
object[] Objects = new object[2];
Objects[0] = new Class1();
Objects[1] = new Class2();
Now say I would want to get the Test string from object[0]
How would I retrieve that?
I have tried
Objects[0].GetType().GetProperty("Test"); //Returns a NullReference
Class1or use inheritance and polymorphism. Let both classes inherit the same base class or implement the same interface which has a propertyTest. Then create an array of this class/interface and you can access this property without casting.Class1.TestandClass2.Test? They are static properties, you dont need object to access them. You can access them directly with the class names.Testarestatic, so no inheritance/polymorphism...Objectas type should not be needed often nowadays.