I use VB.NET, and I know that Union usually runs ByRef, but in VB, strings are usually processed as if they were primitive data types.
Therefore, here is the problem:
Sub Main() Dim firstFile, secondFile As String(), resultingFile As New StringBuilder firstFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\1.txt").Split(vbNewLine) secondFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\2.txt").Split(vbNewLine) For Each line As String In firstFile.Union(secondFile) resultingFile.AppendLine(line) Next My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\merged.txt", resultingFile.ToString, True) End Sub
1.txt contains:
b
from
d
e
2.txt contains:
b
from
d
e
e
g
h
I
J
After running the code, I get:
b
from
d
e
b
e
g
h
I
J
Any suggestions for creating the Union function act as its mathematical counterpart?
Zian choy
source share