Interfaces in VB.NET
This article shows how to implement interfaces in VB.NET.
An interface is a skeleton of rules that must be enforced in the inherited types. An interface contains only the signatures of methods, properties, events, indexers, and delegates.
Important Rules of Interfaces
- An interface can inherit from one or more base interfaces.
- An interface or class inherited from more than one base interfaces is called multiple inheritance.
- A derived class must implement all interface members.
The following code snippet creates two interfaces IList and ICounter. The IListCounter interface is inherited from both IList and ICounter interfaces.
Property Count() As Integer
Sub Count(ByVal i As Integer)
The TestInterface module shows how to use IList and ICounter interface members through IListCounter.
Sub F(ByVal x As IListCounter)
CType(x, IList).Count = 1 ' Ok, invokes IList.Count.
CType(x, ICounter).Count(1) ' Ok, invokes ICounter.Count.