0

次の行に常にこのエラーメッセージが表示されます。

  Casttoenum(this.Polygontype);

ネストされた型 'WindowsPhoneGame2.Containerclass.PolygonContainer' を介して外部型 'WindowsPhoneGame2.Containerclass' の非静的メンバーにアクセスできません

なにが問題ですか?PolygonContainer から public void Casttoenum を呼び出すにはどうすればよいですか?

この問題を解決する最善の方法は何ですか?

    public List<PolygonContainer> PolygonList = new List<PolygonContainer>();
    public struct PolygonContainer
    {
        public float PolygonpositionX;
        public float PolygonpositionY;
        public float Polygonrotation;
        public int Polygontype;

        public PolygonContainer(float polygonpositionx, float polygonpositiony, float polygonrotation, int polygontype)
            : this()
        {
            this.PolygonpositionX = polygonpositionx;
            this.PolygonpositionY = polygonpositiony;
            this.Polygonrotation = polygonrotation;
            this.Polygontype = polygontype;
            Casttoenum(this.Polygontype);
        }
    }

    public enum Polygontypes
    {
        PolyState1 = 1,
        PolyState2 = 2,
        PolyState3 = 3
    }

    private Polygontypes currentPolygontype;

    public void Casttoenum(int state)
    {
       currentPolygontype = (Polygontypes)state;                                     
       WhichPolygon(currentPolygontype);
    }

    public List<Vertices> Polyglist = new List<Vertices>();

    public void WhichPolygon(Polygontypes polyliststate)
    {
        switch (polyliststate)
        {
            case Polygontypes.PolyState1:
                Polyglist = list1;
                break;
            case Polygontypes.PolyState2:
                Polyglist = list2;
                break;
            case Polygontypes.PolyState3:
            Polyglist = list3;
                break;
        }
    }
4

1 に答える 1

0

int を取る代わりにメソッド宣言で Polygontypes (enum) を直接取るので、キャストを避けることができます。

PolygonContainer() を次のように変更します。

public PolygonContainer(float polygonpositionx, float polygonpositiony, float polygonrotation, Polygontypes polygontype)

次に、列挙型へのキャストに使用される次のステートメントを削除します。

this.Polygontype = polygontype; 
Casttoenum(this.Polygontype);

PolygonContainer() 関数を呼び出すときは、無効な値を渡すことができないように、int の最後のパラメーターとして列挙値を渡す必要があります。

于 2013-11-01T12:53:06.183 に答える