Hi, I've got the following question.
I've got one class "Instellingen" that's a field in 3 other classes
public class Instellingen
{
private int _ID;
}
public class Class1: Button
{
private Instellingen _Instellingen;
}
public class Class2 : Label
{
private Instellingen _Instellingen;
}
public class Class3 : TextBox
{
private Instellingen _Instellingen;
}
If I've got another class, that uses the other classes (but it can be anyone of this 3 classes) Do i have to use a switch? or is there an easier way?
public class AnotherClass
{
public AnotherClass ()
{
GetInstellingenFromClass(new Class1());
GetInstellingenFromClass(new Class2());
GetInstellingenFromClass(new Class3());
}
private void GetInstellingenFromClass(Control c)
{
switch (c.GetType.ToString())
{
case "Class1":
Class1 klasse = (Class1) c;
//Do something with the _Instellingen of this class
break;
case "Class2":
Class2 klasse2 = (Class2) c;
//Do something with the _Instellingen of this class
break;
case "Class3":
Class3 klasse3 = (Class3)c;
//Do something with the _Instellingen of this class
break;
}
}
}
(does there exists something so i can just do something like c._Instellingen --> without converting it first to the right type, where it doesn't matter what type c is?)
I hope you understand my question.
Thanks