I have an interface defined in C#
project:
public interface IForm
{
bool IsDisposed { get; }
void Show();
}
I implemen
Use the shadows keyword if you want to override the standard methods of the Form and replace them with the ones defined in your interface otherwise you are required to use a different name as they are treated as two separate methods.
Public Class Form1
Inherits Form
Implements IForm
Public Shadows Property IsDisposed As Boolean Implements IForm.IsDisposed
Public Shadows Sub Show() Implements IForm.Show
' replaces original method in Form class
End Sub
End Class
Alternative:
Public Class Form2
Inherits Form
Implements IForm
Public Property IsDisposed1 As Boolean Implements IForm.IsDisposed
Public Sub Show1() Implements IForm.Show
Me.Show() ' Original method still exists and is accessible like this
End Sub
End Class
VB does not have implicit interface implementation, only explicit while C# supports both.
This means that you have to explicitly say exactly what member that implements an interface member. This adds some flexibility, for example you can make the method that implements an interface member private or protected and you can give it a name that differs from the interface member.
You can read more about the details of this here: http://ondevelopment.blogspot.se/2008/10/implementing-interfaces-in-vbnet.html
VB.NET allows you to name a function/sub differently than the function/sub that it implements. This means that you must explicitly add the Implements <Function/Sub>
to the end of the signature.
In C# you can't do this, so the implementations "just work" without you having to add anything.
MSDN:
The parameter types and return types of the implementing member must match the interface property or member declaration in the interface. The most common way to implement an element of an interface is with a member that has the same name as the interface