我正在调用一种方法来删除包含特定值的对象。它看起来像这样:
static public void RemovePiece(string BoardId)
{
LumberPiece board = LocateBoard(BoardId);
board = null;
}
LumberPiece 是一个如下所示的类:
private class LumberPiece
{
public string boardID;
...
}
LocateBoard 是一个返回正确识别的 LumberPiece 对象的函数:
static private LumberPiece LocateBoard(string BoardId)
{
if (SawyerArea.lumber.boardID == BoardId)
return SawyerArea.lumber;
else if (SpliceArea1.lumber.boardID == BoardId)
return SpliceArea1.lumber;
else if (SpliceArea2.lumber.boardID == BoardId)
return SpliceArea2.lumber;
else
throw new Exception("Your LumberID was not found in any activity area. Has it already been removed? or are you handling the integer-String Conversion Correctly");
}
区域变量是此类的实例:
private class ActivityArea
{
public Sensor sensor;
public ClampSet clampSet;
public Servo servo;
public LumberPiece lumber;
public bool IsCurrentlyFilled()
{
if (lumber != null)
return true;
else
return false;
}
public ActivityArea(Sensor s, ClampSet cs, Servo srv)
{
sensor = s;
clampSet = cs;
servo = srv;
}
如何删除正确识别的 LumberPiece 对象?