Tôi đang sử dụng VB .NET và tôi biết rằng Union thường hoạt động ByRef nhưng trong VB, Strings thường được xử lý như thể chúng là kiểu dữ liệu nguyên thủy.Tại sao chức năng Liên minh trong LINQ không xóa các mục trùng lặp?
Do đó, đây là vấn đề:
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 chứa:
một
b
c
d
e
2.txt chứa:
b
c
d
e
f
g
h
i
j
Sau khi chạy mã, tôi nhận được:
một
b
c
d
e
b
f
g
h
i
j
Mọi góp ý để làm chức năng hành Liên minh như người đồng toán học của nó?
Bạn đã tìm thấy sự cố. Cám ơn rất nhiều! –