日期:2014-05-17 浏览次数:21070 次
[Serializable] public class Program { private const string Path = "temp.xml"; private static Program p = new Program(); private string _userName; public static string UserName { get { return p._userName; } set { p._userName = value; } } private string _userPwd; public static string UserPwd { get { return p._userPwd; } set { p._userPwd = value; } } public Program() { } public void Serializable() { using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + Path, FileMode.Create, FileAccess.Write, FileShare.None)) { XmlSerializer xs = new XmlSerializer(typeof(Program)); xs.Serialize(fs, p); } } public static void Save() { p.Serializable(); } static void Main(string[] args) { Program.UserName = "aaa"; Program.UserPwd = "bbb"; Program.Save(); } }