序列化和读取对象列表的最佳方法是什么?

时间:2018-06-07 03:54:34

标签: c#

我需要序列化,反序列化,读取,写入对象列表Employee。我尝试使用json.net,但它有问题。有什么建议吗?

class Employee
        {
            public string First_name { get; set; }
            public string Last_name { get; set; }
            public string Gender { get; set; }
            public int Pin { get; set; }
            public bool Active { get; set; }
            public bool SignInStatus { get; set; }
            public string Department { get; set; }
            public DateTime SignInTime { get; set; }
            public DateTime SignOutTime { get; set; }
            public DateTime BreakSignInTime { get; set; }
            public DateTime BreakSignOutTime { get; set; }
            public double BreakTimeElasped { get; set; }
            public bool BreakStatus { get; set; }
            public double SessionTimeElasped { get; set; }


            public static List<Employee> EmployeeDatabase = new List<Employee>();

构造函数:

            public Employee(string firstname, string lastname, int pin, string department, string gender, bool active)
            {
                this.First_name = firstname;
                this.Last_name = lastname;
                this.Pin = pin;
                this.Department = department;
                this.Gender = gender;
                this.Active = active;


            }

创建对象并添加到列表

的方法
            public static void CreateNewEmployee(string firstname, string lastname, int pin, string department, string gender, bool active)
            {



                if (Employee.EmployeeDatabase.Count > 0)
                {

                    EmployeeDatabase.Add(new Employee(firstname, lastname, pin, department, gender, active));
                    int indexz = EmployeeDatabase.Count - 1;

                }
                else
                    EmployeeDatabase.Add(new Employee(firstname, lastname, pin, department, gender, active))

0 个答案:

没有答案