using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Xml.Serialization; using System.Xml; namespace XMLSerlizer { class Program { static void Main(string[] args) { List<Vehicle> lstVeh = new List<Vehicle>(); Vehicle v = new Vehicle(); v.id = 1; v.Name = "ZXen"; v.company = "Maruti"; lstVeh.Add(v); Vehicle v1 = new Vehicle(); v1.id = 1; v1.Name = "Fabia"; v1.company = "Scoda"; lstVeh.Add(v1); SerializeObject(lstVeh); } public static void SerializeObject<T>(T obj) { XmlSerializer xs = new XmlSerializer(typeof(T)); XmlWriter wrt = XmlWriter.Create(@"c:\temp.xml"); xs.Serialize(wrt, obj); wrt.Close(); } } public class Vehicle { public int id; public string Name; public string company; } }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: