I am writing the below structure in to the file using Binary Writer.
File Structure:
Num of Employees {employee num & name, employee1 num & name, employee2 num & name…}.
I will get a command with employee num to delete that particualr employee details and update Num of employees feild accordingly.
What is the best way to do the above operation?
Regards
Raju
The question is a little unclear, but when I’m working with a File I always try to deserialize structued data like that to classes.
In general, you’d get a list of Employee objects from the file, remove the item you want, and then write the list back out to the file (or DB, or any other thing you need to write the data to). Quick example (I haven’t tried this, so it might not compile as is:)
for(int i = EmpList.Count -1; i>= 0; i--)
{
if(EmpList[i].EmployeeNumber == employeeNumber)
EmpList.Remove(EmpList[i]);
}
//Call code to reserialize (to file, db, whatever)
}