using System.Xml.Serialization;
public static void Main()
Employee obj=new Employee(){EmpId=100,EmpName="Dharmendra",PhoneNumber="9958606758",Address="Delhi"};
Console.WriteLine(obj.CreateXml(obj));
obj=(Employee)obj.CreateObject(obj.CreateXml(obj),obj);
Console.WriteLine(obj.EmpName);
Console.WriteLine(obj.PhoneNumber + "," + obj.Address);
Console.WriteLine("Hello World");
public int EmpId {get;set;}
public string EmpName{get;set;}
public string PhoneNumber{get;set;}
public String Address {get;set;}
public string CreateXml(object obj)
XmlDocument xmlDoc=new XmlDocument();
XmlSerializer xmlSerializer=new XmlSerializer(obj.GetType());
using(MemoryStream xmlStream=new MemoryStream())
xmlSerializer.Serialize(xmlStream,obj);
public object CreateObject(string xmlString,Object obj)
XmlSerializer oxmlSerializer=new XmlSerializer(obj.GetType());
obj=oxmlSerializer.Deserialize(new StringReader(xmlString));