我在 Icloneable 接口中调用时遇到了一个小问题
我已经告诉班级我想这样使用接口:
class UnitClass: ICloneable
并已放置在克隆功能中
public Object Clone()
{
return this.MemberwiseClone();
}
但是由于某种原因,程序告诉我我没有实现 System.ICloneable.clone() 我什至尝试给函数指定明确的名称,就像这样......
public Object System.ICloneable.Clone()
但效果不大,有人知道我做错了什么吗?
编辑:全班
class UnitClass: ICloneable
{
//-----------------------------------------------------------------------------------------------
//----------------------------------------------Variables----------------------------------------
private int unitID; //added for xml
private string unitName;
private int unitBaseHP;
private int unitCurrentHP;
private Carrier unitCarrier;
private int unitRechargeTime;
private int turnLastPlayed;
private int strengthAgainstFighters;
private int strengthAgainstBombers;
private int strengthAgainstTurrets;
private int strengthAgainstCarriers;
//-----------------------------------------------------------------------------------------------
//---------------------------------------------Constructor---------------------------------------
public UnitClass()
{
unitID = 0;
unitName = "Name Not Set";
unitBaseHP = 0;
unitCurrentHP = 0;
unitCarrier = null;//Carrier works as faction ie red/blue or left/right
unitRechargeTime = 0;
turnLastPlayed = 0;
strengthAgainstFighters = 0;
strengthAgainstBombers = 0;
strengthAgainstTurrets = 0;
strengthAgainstCarriers = 0;
}
//-----------------------------------------------------------------------------------------------
//---------------------------------------------Gets and Sets-------------------------------------
public int UnitID//public
{
set { unitID = value; }
get { return unitID; }
}
public string UnitName//public
{
set { unitName = value; }
get { return unitName; }
}
public int UnitBaseHP//public
{
set { unitBaseHP = value; }
get { return unitBaseHP; }
}
public int UnitCurrentHP//public
{
set { unitCurrentHP = value; }
get { return unitCurrentHP; }
}
public Carrier UnitCarrier//public
{
set { unitCarrier = value; }
get { return unitCarrier; }
}
public int UnitRechargeTime//public
{
set { unitRechargeTime = value; }
get { return unitRechargeTime; }
}
public int TurnLastPlayed//public
{
set { turnLastPlayed = value; }
get { return turnLastPlayed; }
}
public int StrengthAgainstFighters//public
{
set { strengthAgainstFighters = value; }
get { return strengthAgainstFighters; }
}
public int StrengthAgainstBombers//public
{
set { strengthAgainstBombers = value; }
get { return strengthAgainstBombers; }
}
public int StrengthAgainstTurrets//public
{
set { strengthAgainstTurrets = value; }
get { return strengthAgainstTurrets; }
}
public int StrengthAgainstCarriers//public
{
set { strengthAgainstCarriers = value; }
get { return strengthAgainstCarriers; }
}
//---------------------------------------------------------------------------
public object Clone()
{
return this.MemberwiseClone();
}
}