在我的应用程序中,我通过将列表转换为数组将数据写入文本文件,稍后我想通过将其转换为相同的列表类型来加载它并像这样返回它。
我的代码:
public abstract class PhoneBookCore
{
protected string _group;
public PhoneBookCore(string group)
{
this._group = group;
}
}
public class Group : PhoneBookCore
{
private List<PhoneBookCore> elements = new List<PhoneBookCore>();
public List<PhoneBookCore> elementsList {
get { return new List<PhoneBookCore>(elements); }
}
public Group(string name)
: base(name)
{
}
class DataOptions
{
public void Save(Group g)
{
string[] lines = g.elementsList.ConvertAll(p => p.ToString()).ToArray();
File.WriteAllLines(path, lines);
}
public Group Load()
{
string[] buffer = File.ReadAllLines(path); // ----> How do I convert it back
// to list of type group?
return ;
}
}
如何将其转换回类型组列表?