兩個文件行我有兩個文件:FILE1.TXT和FILE2.TXT比較相同數量的
FILE1.TXT內容
this is line 1
this is line 1
this is line 3
FILE2.TXT內容
this is line 1
this is line 2
this is line 4
我想要做的是將file1.txt中的第1行與file2.txt中的第1行進行比較等等。如果兩行不同於僅從file2.txt回顯行
這是我的代碼。
int line_number = 0;
string line_file1, line_file2;
System.IO.StreamReader file2 = new System.IO.StreamReader("file2.txt");
System.IO.StreamReader file1 = new System.IO.StreamReader("file1.txt");
while (((line_file2 = file2.ReadLine()) != null) && ((line_file1 = file1.ReadLine()) != null))
{
if (line_file2 != line_file1)
{
Console.WriteLine(line_file2);
}
line_number++;
}
file2.Close();
file1.Close();
此輸出:
this is line 2
this is line 4
請讓我知道,如果你知道一個解決方案或一個更好的辦法。
什麼是你必須解決這個問題?你的讀者應該真的在使用',但除此之外看起來很好。 – Servy
真的比較File1中的第1行和File2中的第2行。難道不是將File1中的第1行與File2中的第1行進行比較? –
「file1.txt中的第1行與file2.txt中的第2行」 - 您是指file2.txt中的第2行,還是您打算在兩邊都說第1行? –