构造函数部分:
StreamReader sr = new StreamReader("nb.abc");
string[] sss = sr.ReadToEnd().Split('|');
foreach (string s in sss)
{
if (s.Length > 0)
{
comboBox1.Items.Add(s);
}
}
if (comboBox1.Items.Count > 0)
{
comboBox1.SelectedIndex = 0;
}
sr.Dispose();
方法部分:
if (checkBox1.Checked)
{
StreamReader sr = new StreamReader("nb.abc");
string names = sr.ReadToEnd();
sr.Dispose();
if (!names.Contains(u.UserName))
{
StreamWriter sw = new StreamWriter("nb.abc");
sw.Write(u.UserName + "|" + names);
sw.Flush();
sw.Dispose();
}
}