将做工程过程常用的代码段做个收藏,下面代码段是关于C# 重写ToString()方法输出私有变量的片段的代码。
public class MyClass
{
private string customer ="";
private int customerID = 0;
public string Customer
{
get { return customer; }
set { customer = value; }
}
public int CustomerID
{
get { return customerID; }
set { customerID = value; }
}
public override string ToString()
{
return string.Format (“Customer = {0} ID = {1}”, Customer, CustomerID);
}
}