对于我的程序,我创建了一个名为FinishedPiece
的新类,其中包含一些公共变量可供主程序使用。例如:
class FinishedPiece
{
private double _PieceLength;
public double PieceLength
{
get { return _PieceLength; }
set { _PieceLength = value; }
}
}
这一切都很好运作,因为我可以声明一个新的
FinishedPiece
并添加属性:FinishedPiece piece = new FinishedPiece();
piece.PieceLength = 48.25;
我的问题是,如何使用
枚举
完成同样的操作?如果我这样做public enum Cut
{
Angle = 0,
Straight = 1,
AngleThenStraight = 2,
StraightThenAngle = 3
};
那么我希望将其更改为以下内容:piece.Cut = Cut.Angle;
,但我只能通过声明一个新的FinishedPiece.Cut
对象来进行更改:
FinishedPiece.Cut cut = new FinishedPiece.Cut();
cut = FinishedPiece.Cut.Angle;
我应该如何将enum
变量放入一个变量中,以便我可以执行piece.Cut = Cut.Angle
这样的操作?我认为做如下操作是有意义的,但它似乎不起作用。
public int Cut
{
get { return _Cut; }
set { _Cut = value; }
}
private enum _Cut
{
Angle = 0,
Straight = 1,
AngleThenStraight = 2,
StraightThenAngle = 3
};
提前表示感谢!如果我的问题不清楚,请告诉我,我会尽力帮助。
FinishedPiece
没有公共变量。它包含一个私有变量,该变量支持一个公共 属性。 - Jon Skeet