SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 66 | Next

Scott Klein

"Professional LINQ"

Very slick.
Visual Basic
Extension methods are new to Visual Basic 2008. C# has had them for a while, and fortunately Visual
Basic .NET gets them this release. In Visual Basic .NET, extension methods are accessed via the
System.Runtime.CompilerServices namespace, so be sure to include the appropriate Imports statement.
Extension methods can be a Sub or a Function and must be tagged with the
attribute.
The following shows the extension method from the previous example in Visual Basic .NET syntax:
Namespace MyExtensionMethods
Public Class MyExtensions
_
Public Shared Function WordCount(Me ByVal str As System.String) As Integer
Return str.Split(Nothing).Length
End Function
_
Public Shared Function IsValidEmail(Me ByVal email As String) As Boolean
Dim exp As Regex = New Regex("^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")
Return exp.IsMatch(email)
End Function
End Class
End Namespace
Best Practices
Try to implement extension methods only when absolutely necessary and even then, very judiciously.
Your best bet is to create a new type that is derived from an existing type.


Pages:
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6