Monday, January 5, 2009

Extension methods in .NET 3.5 - An easy alternative to inheritance or wrapper class for adding more functionality to base class...

Check the code attached...

{code}

Imports System.Runtime.CompilerServices
Module Module1
Sub Main()
Dim mystring1 As String = "Hello "
Dim mystring2 As String = "World!!"
Dim finalstring As String = ""
Console.WriteLine(finalstring.AcmeConcateString(mystring1, mystring2))
Console.ReadLine()
End Sub

End Module

Public Module AcmeStringHelpers
<extension()> _
Public Function AcmeConcateString(ByVal GenericParamString As String, ByVal s1 As String, ByVal s2 As String) As String
Return s1 & s2
End Function
End Module


{code}

Easy to understand huh!

No comments:

Post a Comment