【发布时间】:2015-02-06 22:15:28
【问题描述】:
好的,所以目前我有这段代码,我试着把 ss 放在引号所在的地方,上面写着“我想在哪里添加 SS”,但它没有用,所以我调查了这个问题,但没有任何帮助已经来找你们了。我把我的最后一个问题搞砸了,所以我希望我能在这个问题上做得很好,但无论如何,这是我当前使用的代码,基于Eric Lippert's blog post
Public Class Form1
Private Function CartesianProduct(Of T)(ParamArray sequences As T()()) As T()()
' base case:
Dim result As IEnumerable(Of T()) = {New T() {}}
For Each sequence 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
Dim s1 As String() = New String() {"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"}
Dim s2 As String() = New String() {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
Dim ss As String()() = CartesianProduct(s1, s1, s2, s2, s2, s2, s1, s1)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text + "000" + "Where I want SS to be added to"
End Sub
结束类
【问题讨论】:
-
您希望它在输出中的格式如何?
-
就像文本一样,如果你看看 ss 是如何制作的,我希望它按照上面使用的顺序出现,所以一个例子是 xx1234xx,我希望它添加到列表框中000 之前,所以我可以使用 Notepad++ 将其变为列表形式
-
我注意到这些是单字符的字符串。如果将它们定义为字符而不是字符串,则实际上可以大大提高效率。
-
供您参考,建议在 Visual Basic 中使用的字符串连接运算符为
&,而不是+。 stackoverflow.com/questions/734600/…