I have this "result" var which is a IEnumerable
type:
Dim result = GetCombinations(TextBox1.Text, StringLength)
To get/write the content of the variable I need to iterate all the items inside using a For and then convert each item to an array, like this:
For Each item In result
RichTextBox1.Text += vbNewLine & item.ToArray
Application.DoEvents()
Next
...So my answer is If I can improve my code for example to join the IEnumerable content to do something like this else:
RichTextBox1.Text = String.Join(vbNewLine, result) ' This does not work.
I mean, a "in one go" thing.
If not, any alternative better (faster) than the For?
UPDATE
This is the full code:
Private Shared Function GetCombinations(Of T)(list As IEnumerable(Of T), length As Integer) As IEnumerable(Of IEnumerable(Of T))
If length = 1 Then
Return list.[Select](Function(x) New T() {x})
Else
Return GetCombinations(list, length - 1).SelectMany(Function(x) list, Function(t1, t2) t1.Concat(New T() {t2}))
End If
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Clear()
Dim result = GetCombinations("abc", 5)
' Dim result2 As IEnumerable(Of String) = result.Select(Function(item) New String(item))
' RichTextBox1.Text = String.Join(vbNewLine, result)
For Each item In result
RichTextBox1.Text &= vbNewLine & item.ToArray
' Application.DoEvents()
Next
End Sub
UPDATE 2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Method result
Dim result As IEnumerable = Permute_Characters("abc", 2)
' Combine strings into lines
' Dont work
RichTextBox1.Text = String.Join(Environment.NewLine, result.ToString.ToArray)
End Sub
See Question&Answers more detail:os