0% found this document useful (0 votes)
28 views

Program

This C# program contains methods to append data to a CSV file and read data from that CSV file. It appends employee data from an EmployeeInfo list to an EmployeeInfo.csv file. It then reads the data from the CSV file, splits each line into values, creates Employee objects, and adds them to a list. The list of employees is then printed to the console.

Uploaded by

Satish Patil
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Program

This C# program contains methods to append data to a CSV file and read data from that CSV file. It appends employee data from an EmployeeInfo list to an EmployeeInfo.csv file. It then reads the data from the CSV file, splits each line into values, creates Employee objects, and adds them to a list. The list of employees is then printed to the console.

Uploaded by

Satish Patil
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.IO;
using System.Collections.Generic;
using Generic3.Model;

namespace Generic3
{
public class Program
{
static void Main(string[] args)
{
AppendCSVFile();
ReadCSVFile();
Console.ReadLine();

}
static void AppendCSVFile()
{
var list = EmployeeData.EmployeeInfo();
foreach(var i in list)
{
File.AppendAllText("EmployeeInfo.csv", $"{i.EmployeeID},
{i.EmployeeName}, {i.Designation},{i.DepartmentName}, {i.JoiningDate} \n");
}
}
static void ReadCSVFile()
{

var lines = File.ReadAllLines("EmployeeInfo.csv");


var list = new List<Employee> ();
foreach (var line in lines)
{
var value = line.Split(" , ");
var employee = new Employee() { EmployeeID =
Convert.ToInt32(value[0]), EmployeeName = value[1] , Designation = value [2],
DepartmentName = value[3], JoiningDate = Convert.ToDateTime(value[4])};
list.Add(employee);
}
list.ForEach(x => Console.WriteLine($"{x.EmployeeID} \t
{x.EmployeeName} \t {x.Designation} \t {x.DepartmentName} \t {x.JoiningDate}"));
}
}
}

You might also like