我目前正在尝试制作一个小程序,将用户在文本框中的输入存储到文件中,但不知何故我无法将输入保存到文件中,这就是我到目前为止所做的:
头等舱:
class Name
{
private string SongName;
private string ArtistName;
//Constructor
public Name(string SongName, string ArtistName)
{
this.ArtistName = ArtistName;
this.SongName = SongName;
}
//Properties for SongName
public string songName
{
get { return SongName; }
set { SongName = value; }
}
//Properties for ArtistName
public string artistName
{
get { return ArtistName; }
set { ArtistName = value; }
}
}
这是 Form1 代码:
public Form1()
{
InitializeComponent();
}
private string SongName, ArtistName;
public void Registry()
{
List<Name> MusicList = new List<Name>();
MusicList.Add(new Name(SongName = txtSongName.Text , ArtistName = txtArtistName.Text)); //Add new elements to the NameClass
//Save the list
StreamWriter FileSaving = new StreamWriter("MusicList");
for (int i = 0; i < MusicList.Count; i++)
{
string sName = MusicList[i].songName;
string aName = MusicList[i].artistName;
}
FileSaving.Close();
}
private void btnEnter_Click(object sender, EventArgs e)
{
Registry();
//Set the textbox to emty so the user can enter new data
txtArtistName.Text = "";
txtSongName.Text = "";
}