Modify the following CustomerDB class, using C# code, to use BinaryReader and…
- User
Modify the following CustomerDB class, using C# code, to use BinaryReader and BinaryWriter to read and write Customer data to a file. There is a windows form with TextBox fields named txtFirstName, txtLastName, and txtEmail where a user can enter data. The windows form has two buttons, btnSave and btnCancel.
Use the included ProductDB as a template and modify CustomerDB in the same style.
namespace CustomerMaintenance { public static class CustomerDB { private const string Dir = @"C:\C#\files"; private const string Path = Dir + "Customers.dat";
codepublic static void SaveCustomers(List<Customer> customers) { using BinaryWriter binaryOut = new( new FileStream(Path, FileMode.Create, FileAccess.Write)); foreach (Customer customer in customers) { } } public static List<Customer> GetCustomers() { List<Customer> customers = new(); if (!Directory.Exists(Dir)) Directory.CreateDirectory(Dir); using BinaryReader binaryIn = new( new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Read)); while (binaryIn.PeekChar() != -1) { Customer customer = new() { }; customers.Add(customer); } return customers; } }}
namespace ProductMaintenance;
public class ProductDB { private const string Dir = @"C:\C#\Files"; private const string Path = Dir + "Products.dat";
codepublic static List<Product> GetProducts() { if (!Directory.Exists(Dir)) Directory.CreateDirectory(Dir); using BinaryReader binaryIn = new( new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Read)); List<Product> products = new();while (binaryIn.PeekChar() != -1) { Product product = new() { Code = binaryIn.ReadString(), Description = binaryIn.ReadString(), Price = binaryIn.ReadDecimal() }; products.Add(product); }
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.