Here is updated Case 1, please check
using System;
using System.IO;
namespace ConsoleApplication1
{
class textread
{
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
public static Employee Adding()
{
Employee employeeDetail = new Employee();
Console.Write("Employee Id:");
employeeDetail.Id = int.Parse(Console.ReadLine());
Console.Write("Employee Name:");
employeeDetail.Name = Console.ReadLine();
Console.Write("Employee Address:");
employeeDetail.Address = Console.ReadLine();
return employeeDetail;
}
public static void Main(string[] args)
{
string pathString = @"D:\temp\MyNewFile.txt";
Boolean p = true;
while (p)
{
Console.WriteLine("Employee Record Managemnet system");
Console.WriteLine("1)Add");
Console.WriteLine("2)Edit");
Console.WriteLine("3)Dispaly");
Console.WriteLine("4)Delete");
Console.WriteLine("Select operation");
int option = int.Parse(Console.ReadLine());
switch (option)
{
case 1:
TextWriter tw = new StreamWriter(@"D:\temp\MyNewFile.txt");
var outObj = Adding();
string tempStr = "Id: " + outObj.Id + Environment.NewLine + "Emp Name: " + outObj.Name + Environment.NewLine + "Emp Address: " + outObj.Address;
tw.Write(tempStr);
tw.Close();
break;
case 2:
TextReader tr = new StreamReader(@"D:\temp\MyNewFile.txt");
Console.WriteLine(tr.ReadLine());
Console.WriteLine(tr.ReadToEnd());
tr.Close();
break;
}
}
}
}
}