From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

LINQ: Enumerable and extension methods

LINQ: Enumerable and extension methods - Visual Basic Tutorial

From the course: Visual Basic Essential Training

LINQ: Enumerable and extension methods

- [Instructor] Extension methods are a feature in Visual Basic that let us add new methods to existing types as if they were part of the original type. They are especially useful when we need to enhance the functionality of types provided by external libraries for the .NET framework without altering the original source code. It's important to note that extension methods are not implemented through object inheritance. You are neither deriving a new type nor extending the class using traditional object-oriented inheritance. Instead, they provide a way to extend functionality in a non-intrusive manner. To define an extension method in Visual Basic, we need to declare it within a module that makes it shared across other files, and we use the extension attribute. You can see that on line six. Now in .NET, an attribute is a way of adding extra metadata to a .NET assembly. What this essentially does is say that we're opting into having this function, ToTitleCase, be an extension method. The…

Contents