Inheritance in C# (class + interface)
-
Hi all, I have a class which inherit from System.WindowsForm.UserControl and an interface (with a method named Update) I want to implement the Update method of my interface and not the user control method is there a way to do that ? like in C++ void Interface::Update() ? :doh: Thanks in advance
-
Hi all, I have a class which inherit from System.WindowsForm.UserControl and an interface (with a method named Update) I want to implement the Update method of my interface and not the user control method is there a way to do that ? like in C++ void Interface::Update() ? :doh: Thanks in advance
You can have two update methods.
public void Update()
{
// This is the first version
}public void IMyInterface.Update()
{
// This is the second version
}MyControl control = GetControl(); // Do what is needed to create the control
control.Update(); // This will call the first version
((IMyInterface)control).Update(); // This will call the second version
The version called depends on what you have a reference to. If you have a reference to the class or one of its bases then the
Update()
method will be called, if you have a reference to the interface theIMyInterface.Update()
will be called.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website