Passing Interfaces as Method Arguments
One of the most powerful features when working with interfaces is that methods can receive interfaces as parameters. This means that you can pass in any object as these parameters so long as it implements the given interface. The following example shows a method that accepts an argument of type IList
, meaning that any object implementing the IList
interface can be accepted:
'Interfaces as parametersPublic Class WorkWithLists Public Function Elaborate(items As IList) As Integer 'Just for demo, returns 0 if the list contains something If items.Count > 0 Then Return 0 Else 'if not, adds a new object to the list Dim item As ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.