using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace SimpleXMLSerialize
{
public class Employee
{
public int EID { get; set; }
public string EName { get; set; }
public string Designation { get; set; }
public long Phone { get; set; }
}
public class SXML
{
public static void Main(string[] args)
{
List<Employee> Emplist = new List<Employee>();
Employee emp1 = new Employee();
emp1.EID = 1;
emp1.EName = "Naveen";
emp1.Designation = "QA";
emp1.Phone = 9895356522;
Employee emp2 = new Employee();
emp2.EID = 2;
emp2.EName = "Balu";
emp2.Designation = "Software Developer";
emp2.Phone = 9232546554;
Emplist.Add(emp1);
Emplist.Add(emp2);
Serialize(Emplist);==============>> ERROR
}
public void Serialize(List<Employee> list)
{
XmlSerializer xmlser = new XmlSerializer(typeof(List<Employee>));
using (StreamWriter stmw = new StreamWriter(@"D:\sxml.xml"))
{
xmlser.Serialize(stmw, list);
}
}
}
I tried for SERIALIZE buit I got error in this line )serialize(emplist)
Error Shows:object reference is required for non static fileds,method or property
}