'没有实现接口成员'System.ICloneable.Clone()'

时间:2013-02-07 15:17:28

标签: c# icloneable

我在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();
    }
}

1 个答案:

答案 0 :(得分:0)

这对我来说很好。

public class MyClone : ICloneable
{
    public object Clone()
    {
        return this.MemberwiseClone();
    }
}

您可能不想再分享您的课程?什么都没有真正向我跳出来。