私のテキストファイルがリストボックスに表示されない理由を調べることができません。このプログラムは、Vusial Studioを使用して作成されました。構文エラーはなく、私の論理は健全だと私は信じています。なぜあなたが私に助けてくれますか?ここでテキストファイルをリストボックスに読み込むC#
は私のForm1.csのためのコードです:
namespace Jason_T_READER_
{
public partial class Form1 : Form
{
string selectedName = "";
List<PersonEntry> nameList = new List<PersonEntry>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
StreamReader inputfile;
inputfile = File.OpenText("Personlist.txt");
string inRecord;
while (!inputfile.EndOfStream)
{
inRecord = inputfile.ReadLine();
string[] tokens = inRecord.Split(',');
PersonEntry person = new PersonEntry(tokens[0],tokens[1],tokens[2]);
listBox1.Items.Add(person.Name);
PersonEntry friendObj = new PersonEntry(tokens[0],tokens[1],tokens[2]);
nameList.Add(friendObj);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show("Exception in try/catch. ");
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
selectedName = listBox1.SelectedItem.ToString();
PersonInfoForm myPerInfoForm = new PersonInfoForm();
Label label1 = new Label();
label1.Size = new Size(270, 75);
label1.Location = new Point(10, 10);
foreach (PersonEntry PersonEntry in nameList)
{
if (PersonEntry.Name == selectedName)
{
label1.Text += "Name: " + PersonEntry.Name + "\n" +
"Email: " + PersonEntry.Email + "\n" +
"Phone number: " + PersonEntry.PhoneNum;
}
}
myPerInfoForm.Controls.Add(label1);
myPerInfoForm.ShowDialog();
}
}
}
は、これは私のクラスのシートである:ここで
namespace Jason_T_READER_
{
class PersonEntry
{
private string _name;
private string _email;
private string _phoneNum;
public PersonEntry(string name, string email, string phoneNum)
{
_name = name;
_email = email;
_phoneNum = phoneNum;
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public string Email
{
get
{
return _email;
}
set
{
_email = value;
}
}
public string PhoneNum
{
get
{
return _phoneNum;
}
set
{
_phoneNum = value;
}
}
}
}
ですから、ステッピング-の上にコードF-10のキーを使用して、それをデバッグするのですか? –
デバッガのコードをステップ実行すると、何が表示されますか? –
どのようにデバッガをステップ実行しますか? F-10? –