Ich benutze VB.NET und ich weiß, dass Union normalerweise ByRef funktioniert, aber in VB, Strings werden in der Regel so verarbeitet, als ob sie primitive Datentypen waren.Warum entfernt die Union-Funktion in LINQ doppelte Einträge nicht?
Folglich hier ist das 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 enthält:
ein
b
c
d
e
2.txt enthält:
b
c
d
e
f
g
h
i
j
Nachdem der Code ausgeführt wird, erhalte ich:
ein
b
c
d
e
b
f
g
h
i
j
Irgendwelche Vorschläge für die Herstellung der Union Funktion wirken wie ihre mathematische Entsprechung?
Sie haben das Problem gefunden. Vielen Dank! –