public void WriteServerXml(string dir, IList <ServerInfo> list) { var sw = Stopwatch.StartNew(); try { var arrayDataAsXElements = from c in list select new XElement ("Server", new XAttribute("id", c.ID), new XElement("Name", c.Name), new XElement("IP", c.IP), new XElement("Port", c.Port), new XElement("IsCloud", (c.IsCloud == true) ? 1 : 0), new XElement("Factory", c.Factory), new XElement("Longitude", c.Longitude), new XElement("Latitude", c.Latitude), new XElement("IsLogin", (c.IsLogin == true) ? 1 : 0), new XElement("LoginResult", (c.LoginResult == true) ? 0 : 1), new XElement("Permission", c.Permission), new XElement("UserName", c.UserName), new XElement("UserPwd", MyEncrypt.EncryptDES(c.UserPwd)), new XElement("IsSaveUserName", (c.IsSaveUserName == true) ? 1 : 0), new XElement("IsSaveUserPwd", (c.IsSaveUserPwd == true) ? 1 : 0) ); XElement peopleDoc = new XElement("Root", arrayDataAsXElements); var doc = new XDocument(peopleDoc); doc.Save(dir); } catch (Exception ex) { throw ex; } Console.WriteLine("加密消耗时间" + sw.Elapsed.ToString()); }