我有地址簿应用程序,并想将最终结果写入文本文件。我很难将我的列表转换为数组,以便我可以执行WriteAllLines
命令。
界面:
abstract class PhoneBookCore {
protected string _group;
public PhoneBookCore(string group) {
this._group=group;
}
public abstract void Add(PhoneBookCore d);
}
class Contect: PhoneBookCore {
private string _firstName;
private string _lastName;
private string _phoneNumber;
private string _addres;
public Contect(string group, string firstName, string lastName, string phoneNumber, string addres)
: base(group) {
this._firstName=firstName;
this._addres=addres;
this._lastName=lastName;
this._phoneNumber=phoneNumber;
}
}
class Group: PhoneBookCore {
private List<PhoneBookCore> elements=new List<PhoneBookCore>();
public List<PhoneBookCore> elementsList {
get;
set;
}
public Group(string name)
: base(name) {
}
public override void Add(PhoneBookCore d) {
elements.Add(d);
}
}
这是我卡住的地方
class DataOptins {
public string Save(Group g) {
foreach(var item in g) {
string[] arr=g.elementsList.ToArray(); // <---- :(
}
System.IO.File.WriteAllLines(Path, arr); // <---- :(
}
}