我已经多次复习教授的讲座,复习课本,在网上无休止地搜索答案,并尝试了所有合理的建议解决方法。我当然错过了一些东西。地址簿写入列表框,文件被创建,但名称和地址没有写入文件。对我所缺少的任何帮助将不胜感激。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
namespace LAB7A
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<Person> people = new List<Person>();
class Person
{
public string Name
{
get;
set;
}
public string Email
{
get;
set;
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
StreamWriter address = new StreamWriter("addressbook.txt");
address.WriteLine(textBox1.Text, textBox2.Text);
}
catch (DirectoryNotFoundException exc)
{
MessageBox.Show("Directory Could Not Be Found");
}
}
private void button1_Click(object sender, System.EventArgs e)
{
Person p = new Person();
p.Name = textBox1.Text;
p.Email = textBox2.Text;
people.Add(p);
listBox1.Items.Add(p.Name);
listBox1.Items.Add(p.Email);
//StreamWriter address.WriteLine(textBox1.Text);
//address.WriteLine(textBox2.Text);
//listBox1.Items.Add(textBox1.Text);
//listBox1.Items.Add(textBox2.Text);
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}