嗨,我能知道为什么这段代码不起作用,它正在工作,但它也会删除非重复条目,对于某些列表,它会抛出一些错误
前任:
此列表有效,但它也会删除http://test1.com
http://test.com
http://test.com
http://test1.com
http://1test.com
使用此列表将引发此“System.ArgumentNullException 未处理”错误
http://test.com
http://test.com
http://test1.com
http://1test.com
http://etest.com
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog buka = new OpenFileDialog();
buka.InitialDirectory = "";
buka.Filter = "Text files(*.txt)|*.txt|All files (*.*)|*.*";
buka.FilterIndex = 2;
buka.RestoreDirectory = true;
buka.Title = "Cari";
buka.ShowDialog();
string bukafile = buka.FileName;
if (!String.IsNullOrEmpty(bukafile))
{
StreamReader isiFile = File.OpenText(bukafile);
while (isiFile.Peek() != -1)
{
if (!listBox1.Items.Contains(isiFile.ReadLine()))
{
listBox1.Items.Add(isiFile.ReadLine());
}
}
isiFile.Close();
}
}