我想比较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