c# 序列化和反序列化
C# 序列化
/// <summary> /// wangliuzheng /// </summary> public void youTrySerializer() { XmlSerializer xml = new XmlSerializer(typeof(TryClass)); FileStream fstream =new FileStream(@"G://youTry.xml",FileMode.OpenOrCreate); TryClass Youtry = new TryClass(); Youtry.Name = "youTry"; xml.Serialize(fstream,Youtry);// 序列化 fstream.Close(); } /// <summary> /// wangliuzheng /// </summary> /// <returns></returns> public string youTryDeserializer() { XmlSerializer xml = new XmlSerializer(typeof(TryClass)); FileStream fstream = new FileStream(@"G://youTry.xml", FileMode.Open, FileAccess.Read); TryClass Youtry =xml.Deserialize(fstream) as TryClass; // 反序列化 return Youtry.Name.ToString(); } public class TryClass { private string name; public string Name { get { return name; } set { name = value; } } }
wangliuzheng1990@126.com