Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit interface implementation in VB.NET

Tags:

.net

vb.net

How to implement explicit interface implementation in VB.NET?

like image 521
mark vanzuela Avatar asked Oct 16 '09 09:10

mark vanzuela


People also ask

How do you achieve interface implementation in VB net?

To declare the implementation of an interface method, you can use any attributes that are legal on instance method declarations, including Overloads , Overrides , Overridable , Public , Private , Protected , Friend , Protected Friend , MustOverride , Default , and Static .

What is implicit interface implementation?

An implicit interface implementation is where you have a method with the same signature of the interface. An explicit interface implementation is where you explicitly declare which interface the method belongs to.

Does VB Net have interfaces?

However, classes that implement an interface do contain code. Keep in mind that there are no instances of interfaces in VB . NET. Every instance is a type that implements an interface, but is itself not an instance of the interface.

What is meant by interface in VB net?

VB.NET Interfaces So, an interface is nothing but a collection of method and property declarations. An interface can declare only a group of related functionalities, it is the responsibility of the deriving class to implement that functionality. An interface is defined with the Interface keyword.


2 Answers

As others have said, make the routine private, and it forces clients to call through the interfaces.

Just one more word. Explicit interface implementation in C# also allows the programmer to inherit two interfaces that share the same member names and give each interface member a separate implementation. In VB.Net, that's easy, because the implementing methods can have different names from the interface names.

Function ICanUseAnyNameILike() As String Implements IFoo.Bar

Function ItsTotalAnarchy() As String Implements IFoo2.Bar, IFoo3.ItsMadnessReally
like image 118
MarkJ Avatar answered Sep 24 '22 07:09

MarkJ


Just declare sub/function Private:

Private Function Bar() As String Implements IFoo.Bar
like image 33
Anton Gogolev Avatar answered Sep 21 '22 07:09

Anton Gogolev