Public Function Choose(Of T)(ByVal ParamArray Values() As T) As T
Return Choose(Of T)(New System.Random().Next(0, Values.Length - 1), Values)
End Function
Public Function Choose(Of T)(ByVal Index As Integer, ByVal ParamArray Values() As T) As T
Return Values(Index)
End Function
' Exemple d'utilisation :
Dim a1 As String = Choose(Of String)(2, "a", "b", "c", "d") ' a1 = "c"
Dim a2 As String = Choose(Of String)("a", "b", "c", "d") ' a2 = "a", "b", "c" ou "d"
Dim b1 As Integer = Choose(Of Integer)(1, 2, 3, 4) ' b1 = 3
Dim b2 As Integer = Choose(Of Integer)(New Integer() {1, 2, 3, 4}) ' b2 = 1, 2, 3 ou 4
' Provoque une des 4 exceptions
Throw Choose(Of System.Exception)(New System.IO.FileNotFoundException(), _
New System.Runtime.InteropServices.SEHException(), _
New System.Security.SecurityException(), _
New System.Exception("moa"))