Adapting code from Eric Lippert's blog on Cartesian products:
Private Function CartesianProduct(Of T)(ParamArray sequences As T()()) As T()()
' base case:
Dim result As IEnumerable(Of T()) = {New T() {}}
For Each sequence As var In sequences
Dim s = sequence
' don't close over the loop variable
' recursive case: use SelectMany to build the new product out of the old one
result = From seq In result
From item In s
Select seq.Concat({item}).ToArray()
Next
Return result.ToArray()
End Function
Usage:
Dim s1 As String() = New String() {"small", "med", "large", "XL"}
Dim s2 As String() = New String() {"red", "green", "blue"}
Dim s3 As String() = New String() {"Men", "Women"}
Dim ss As String()() = CartesianProduct(s1, s2, s3)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…