【发布时间】:2013-09-16 20:36:52
【问题描述】:
我正在尝试构建一个简单的保存和加载程序,它从文本文件中读取用户,将其添加到可观察的集合中,然后用可观察的用户集合填充列表框。
虽然我了解如何将用户添加到我的可观察集合,然后将该集合写入 txt 文件,但我对如何读取用户并将他重新添加到 ObservableCollection 感到困惑用户。
我的用户类:
public class User
{
public string UserName { get; set; }
public string Password { get; set; }
}
问题方法:
ObservableCollection<User> LoadActionList = new ObservableCollection<User>();
using (System.IO.StreamReader file = new System.IO.StreamReader("SavedAccounts.txt"))
{
string line;
while (!file.EndOfStream)
{
line = file.ReadLine();
//LoadActionList.Add(line); //how to detect that a line is a User?
}
file.Close();
}
有什么想法吗?
【问题讨论】:
标签: c# file-io load save observablecollection