public class Program {static void Main (string[] args) {Student stu1 = new Student () {Name = "Okbase", age = 10}; string xml = Xmlhelper.serializer (typeof (Student), STU1); Console.Write (XML); Student stu2 = Xmlhelper.deserialize (typeof (Student), XML) as Student; Console.Write (String. Format ("name: {0}, Age: {1}", Stu2. Name, STU2. Age)); Console.readkey (); public class Student {public string Name {set; get;} public int Age {set; get;} }///<summary>///Replace the passed-in string middle character with a special character///</summary>//<param name= "value" > string to be replaced </param>//<param name= "Startlen" > Pre-reserved length </param>//<param name= "Endlen" & gt; tail retention length </param>//<param name= "Replacechar" > Special characters </param>//<returns> strings replaced by special characters </returns> private static string REPLACEWITHSPEcialchar (string value, int startlen = 4, int endlen = 4, char Specialchar = ' * ') {try { int lenth = value. Length-startlen-endlen; String replacestr = value. Substring (Startlen, lenth); String specialstr = String. Empty; for (int i = 0; i < replacestr.length; i++) {specialstr + = Specialchar; } value = value. Replace (Replacestr, SPECIALSTR); } catch (Exception) {throw; } return value; } }
How to use
Public classProgram {Static voidMain (string[] args) {Student STU1=NewStudent () {Name ="Okbase", age =Ten }; stringXML = Xmlhelper.serializer (typeof(Student), STU1); Console.Write (XML); Student STU2= Xmlhelper.deserialize (typeof(Student), XML) asStudent; Console.Write (string. Format ("name: {0}, Age: {1}", STU2. Name, STU2. Age)); Console.readkey (); } Public classStudent { Public stringName {Set;Get; } Public intAge {Set;Get; } } }
. NET Xmlhelper Help Classes