Is it possible? Or they must necessarily inherit from the same parent class ...
public interface interfaz
{
}
public class a : interfaz
{
}
public class b : interfaz
{
}
public class prueba
{
public void X()
{
a objetoA = new b();
}
}
The code such that it gives a compilation error since classes a and b are obviously of different types.
Real example;
public partial class ConfigNivel : UserControl
{
public int GetTotal(){};
}
public partial class ConfigCPU : UserControl
{
public int GetTotal(){};
}
These are views that I load in a StackPanel and I would like to always call their method GetTotal()
once they have instantiated them, regardless of the class they are.
NEW EDIT
The views that you load in the StackPanel
can be 3, 4, 5, 6, 7 ... whatever they are, they all inherit from the UserControl class, and all of them have a method called GetTotal()
, which returns the calculation of a sum of properties of that object.
What I want to do is that they are of the class that are able to call their GetTotal () method within a For
or a Foreach
and get the sum of all. The problem I have now is that they are objects of different classes: ConfigNivel
, ConfigCPU
etc ... and I can not use poliformfismo. As they are inheriting from UserControl and C # does not support inheriting of several classes (or so I think) I do not know how to do it ...
I hope you have explained me well.