Imports System.Runtime.CompilerServices Module ExtensionExample Sub Main() Console.WriteLine("ExtensionExample.vb") Console.Write("Enter a number between 1 and 10 ==> ") Dim i As Integer = Integer.Parse(Console.ReadLine()) Console.WriteLine("The value is {0} ", _ IIf(i.CheckRange(1, 10), i, "out of range")) Console.Write("Enter one of these values {CA | NY | TX | FL | NC} ==> ") Dim state As String = Console.ReadLine().ToUpper() Console.WriteLine("The state is {0} ", _ IIf(state.CheckValues("CA", "NY", "TX", "FL", "NC"), state, " not in the list")) Console.WriteLine("End of tester") Console.ReadLine() End Sub End Module Module CheckExtensions ''' ''' Extension method that adds a range checking feature to integer data. ''' ''' The integer value to check. ''' The inclusive low value of the range to check. ''' The inclusive high value of the range to check. ''' Boolean indicating whether or not the value is within the range. _ Public Function CheckRange(ByVal number As Integer, _ ByVal lowValue As Integer, _ ByVal highValue As Integer) _ As Boolean If ((number >= lowValue) AndAlso (number <= highValue)) Then Return True Else Return False End If End Function ''' ''' Extension method that adds a list of values checking feature to string data. ''' ''' The string value to check. ''' A comma-delimited list of string values that are the ''' valid values. ''' Boolean indicating whether or not the value is in the list. _ Public Function CheckValues(ByVal testValue As String, _ ByVal ParamArray values() As String) _ As Boolean If (values.Contains(testValue)) Then Return True Else Return False End If End Function End Module