编写一个计数器类,定义一个私有数据成员,通过两个成员函数,分别使其完成加1和减1操作。
发布网友
发布时间:2022-04-30 02:50
我来回答
共1个回答
热心网友
时间:2023-10-09 00:30
public class Counter
{
private System.Int32 _id;
public Counter()
{
this._id = 0;
}
public Counter(int num)
{
this._id = num;
}
public System.Int32 ID
{
get
{
return this._id;
}
set
{
this._id = value;
}
}
public void AddSelf()
{
this._id = this._id + 1;
}
public void LessSelf()
{
this._id = this._id - 1;
}
}