嗨,这是我第一次在 StackOverflow 上提问。刚开始学习如何编码。我正在制作一个包含三个对象 Customer、Inventory 和 OrderForm 的订购系统。
我必须能够将客户信息(以下字段)添加/保存到 .csv 文件中。通过 StreamWriter。还可以随时编辑和删除特定信息。
现在从我的研究来看,列表似乎是保存信息直到它们被写入文件的最佳方式,而且它们更容易编辑和删除信息
我已经在客户类中声明了一个列表(这是正确的方法吗?)。我现在将如何将所有这些变量添加到列表中?然后能够根据需要编辑或删除它们吗?
感谢帮助。
public class Customer
{
//Holds Customer Info.
List<Customer> custInfo = new List<Customer>();****THIS ONE*******
//Instance Variables
private string custName;
private string custID;
private string custAddress;
private string custState;
private int custZip;
private int custAge;
private decimal totalOrdered;
public Customer()
{ }//default constructor
// retrieve the customer name
public string getCustomerName()
{
return custName;
}//end of getCustomerName method
// set the customer name
public void setCustomerName(string customerName)
{
custName = customerName;
}//end of setCustomerName method
//get customerID
public string getCustID()
{
return custID;
}//end of getCustID
//set CustomerID
public void setCustID(string customerID)
{
custID = customerID;
}//end setCustID
// retrieve the customer address
public string getCustomerAddress()
{
return custAddress;
}//end of getCustomerAddress method
// set the customer address
public void setCustomerAddress(string customerAddress)
{
custAddress = customerAddress;
}//end of setCustomerAddress method
//retrieves customer state
public string getCustState()
{
return custState;
}//end getCustState
//sets customer state
public void setCustState(string customerState)
{
custState = customerState;
}//end setCustState
// retrieve the customer zip
public int getCustomerZip()
{
return custZip;
}//end of getCustomerZip method
// set the customer Zip
public void setCustomerZip(int customerZip)
{
custZip = customerZip;
}//end of setCustomerZip method
//Gets customer age
public int getCustomerAge()
{
return custAge;
}//end getCustomerAge
//sets customer age
public void setCustomerAge(int customerAge)
{
custAge = customerAge;
}//end setCustomerAge
//gets customers total order
public decimal getTotalOrdered()
{
return totalOrdered;
}//end getTotalOrdered
//sets total ordered
public void setTotalOrdered(decimal customerTotal)
{
totalOrdered = customerTotal;
}//end setTotalOrdered
}//end public class Customer