答案 0 :(得分:0)
创建一个类listcontact
,如下所示
namespace TingTong
{
public class contacts
{
public string name { get; set; }
public string image { get; set; }
public string lastmessage { get;set; }
public string unreaded { get; set; }
}
}
然后在您的页面中写下以下内容
List<contacts> listcontact = new List<contacts>();
Xdoc = new XDocument(new XElement("Contacts"));
MessageBox.Show(listcontact.Count.ToString());
for (int i = 0; i < listcontact.Count; i++)
{
XElement xml = new XElement("Contact", new XElement("name", listcontact[i].name), new XElement("image", listcontact[i].image), new XElement("lastmessage", listcontact[i].lastmessage), new XElement("unreaded", listcontact[i].unreaded));
if (Xdoc.Descendants().Count() > 0)
Xdoc.Descendants().First().Add(xml);
else
Xdoc.Add(xml);
}
Xdoc.Save(sub + "\\Contacts\\ContactList.xml");