Generic method maximum returns the largest of three objects : Generic Method « Generics « VB.Net Tutorial






Module MaximumTest
   Sub Main()
      Console.WriteLine(5, Maximum(3, 4, 5))
      Console.WriteLine(Maximum(6.6, 8.8, 7.7))
      Console.WriteLine(Maximum("pear", "apple", "orange"))
   End Sub
   
   Public Function Maximum(Of T As IComparable(Of T))(ByVal x As T, ByVal y As T, ByVal z As T) As
T
      Dim max As T = x
      If y.CompareTo(max) > 0 Then
         max = y
      End If

      If z.CompareTo(max) > 0 Then
         max = z
      End If

      Return max
   End Function
End Module
5
8.8
pear








9.1.Generic Method
9.1.1.Using generic methods to print arrays of different types
9.1.2.Generic method maximum returns the largest of three objects