我想比較WinForms中兩個文件的內容。每個文件都包含每行上帶有名稱和編號的行。我想從第一個文件讀取並與第二個文件進行比較。如果行不相等,我想提取它並將其添加到ArrayList。看看我到目前爲止做了什麼:比較c#中2個文件的內容#
Int32 nr = 0;
String linieinit=" ", liniewrt=" ";
ArrayList newlines = new ArrayList();
using (StreamReader fileinit = new StreamReader(Application.StartupPath + "/bontemp" + label_pin.Tag.ToString() + "initial"))
{
using (StreamReader filewrt = new StreamReader(Application.StartupPath + "/bontemp" + label_pin.Tag.ToString()))
{
while ((linieinit = fileinit.ReadLine()) != null && (liniewrt = filewrt.ReadLine()) != null)
{
Console.WriteLine(linieinit + " " + liniewrt);
if (linieinit.Equals(liniewrt))
{
nr = 0;
}
else
{
nr++;
newlines.Add(liniewrt);
}
}
filewrt.Close();
File.Delete(Application.StartupPath + "/bontemp" + label_pin.Tag.ToString());
}
fileinit.Close();
File.Delete(Application.StartupPath + "/bontemp" + label_pin.Tag.ToString() + "initial");
}
Console.WriteLine(nr);
if (nr == 0)
{
int pozition = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["DenumireProdus"].Value.ToString(), print6B, Brushes.Black, x, 130 + height);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells["produs_cantitate"].Value.ToString(), print6B, Brushes.Black, x + 110, 130 + height);
height += 15;
}
if (pozition > height)
{
pozition = height;
}
}
else
{
for (Int32 j = 0; j < newlines.Count; j++)
{
e.Graphics.DrawString(newlines[j].ToString(), print6B, Brushes.Black, x, 130 + height);
height += 15;
}
}
任何建議我怎麼能使它工作?
就像一個不相關的代碼風格的評論...嵌套使用()語句讓我把我的頭髮,特別是當他們跨越很多的代碼。 – 2012-02-21 19:12:47
問題是? – Magnus 2012-02-21 19:13:28
那麼你需要什麼?什麼是你的[問題](http://stackoverflow.com/faq#questions)? – 2012-02-21 19:16:07