Tutorial by Examples

Extension methods are useful to extend the behaviour of libraries we don't own. They are used similar to instance methods thanks to the compiler's syntactic sugar: Sub Main() Dim stringBuilder = new StringBuilder() 'Extension called directly on the object. stringBuilder.AppendIf(t...
A good use of extension method is to make the language more functional Sub Main() Dim strings = { "One", "Two", "Three" } strings.Join(Environment.NewLine).Print() End Sub <Extension> Public Function Join(strings As IEnumerable(Of String), separa...
Public Module Usage Public Sub LikeThis() Dim iCount As Integer Dim sCount As String iCount = 245 sCount = iCount.PadLeft(4, "0") Console.WriteLine(sCount) Console.ReadKey() End Sub End Module Public Module Padding <Extension> Pub...
Example of calling an extension method as an extension and as a regular method. public Class MyClass Sub Main() 'Extension called directly on the object. Dim Version = Assembly.GetExecutingAssembly.GetVersionFromAssembly() 'Called as a regular method. ...

Page 1 of 1