I'm using VB .NET and I know that Union normally works ByRef but in VB, Strings are generally processed as if they were primitive datatypes.
Consequently, here's 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:
a
b
c
d
e
2.txt contains:
b
c
d
e
f
g
h
i
j
After running the code, I get:
a
b
c
d
e
b
f
g
h
i
j
Any suggestions for making the Union function act like its mathematical counterpart?