.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Extension Methods in .NET Framework 3.5 in VB.NET 9.0

Posted By:Hefin Dsouza       Posted Date: August 13, 2009    Points: 25    Category: .Net Framework    URL: http://www.dotnetspark.com  

Extention Methods is a New Concept of the .NET Framework 3.5 which gives us the capablities to add our own custom methods to DataTypes without diriving from the base class.

The Rules are Little diffrent when we use Extension Methods in VB.NET 9.0

1st Rule :- Extention Methods must only de declared only in Modules.

2nd Rule :- Extension Method can only be a Sub procedure or a Function

3rd Rule :- Extension Methods mustbe marked with a attribute from the System.Runtime.CompilerServices namespace.

4th Rule :- The First parameter of the Extension method defination tells the compiler on which DataType to use the Extension method on.

The Extension Method Module

Imports System.Runtime.CompilerServices

Module Extensions


Public Function ToInteger(ByVal sVal As String) As Integer

Return Convert.ToInt32(sVal)

End Function

End Module

The Class where the Extension Method will be used.
Imports VBExtension

Public Class Class1

Shared Sub Main()

Dim stringValue As String = "100"

Dim s As Integer = stringValue.ToInteger()

End Sub

End Class

Hope This Article has Helped you undertand Extension Methods.Please feel free to comment if you have any doubts.

Hefin Dsouza

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend