O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extension Methods

In principle, it has always been possible to extend classes with new methods or properties. You inherited them and then added new methods or properties in the inherited class code. This worked as long as the following conditions were met:

  • The types were not marked with the NotInheritable modifier (Sealed in C#).

  • The types weren’t value types—because types created with Structure are automatically value types and those are implicitly not inheritable.

To help structure your code better, Microsoft added extension methods in Visual Basic 2008. You can use these to add user-defined functions to already defined data types without having to create a new, inherited type. An extension method is a special kind of static method, but you can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required