0

WindowsPhoneプログラミングを学び始めたばかりです。

私はこのように定義されたリストを持っています、

    private List<Vector2> _terrain;
    public List<Vector2> Terrain { get { return _terrain; } }

この下で、私はこのようないくつかのベクトルでリストを埋めます、

    level.Terrain.Add(new Vector2(i, (int)y));

このリストに50個の要素があるとしましょう。私がやりたいのは、このリストの最初のアイテムを削除してから、2番目のアイテムを最初の場所に移動し、3番目のアイテムを2番目に移動するなどです。これでやりたいのは、ランダムな「もの」を生成することです。 。これで、動いているように見せることを計画しています。ご協力ありがとうございました!

4

4 に答える 4

1

このList<T>クラスは、項目のリストである構造に抽象化を提供しようとします。したがって、アイテムがリストから削除されると、そのアイテムは削除され、リストは自動的に圧縮されます。たとえば、私が持っていた場合:

List<int> numbers = new List<int>();
for (int i = 0; i < 10; i++)
{
   numbers.Add(i+1); //adds the numbers 1 through 10
}

Console.WriteLine(numbers[0]); //writes out 1 - the first item
Console.WriteLine(numbers[3]); //writes out 4 - the fourth item
Console.WriteLine(numbers.Count); //writes out 10 - there are ten elements

numbers.RemoveAt(0); //removes the first element of the list
Console.WriteLine(numbers[0]); //writes out 2 - the new first item
Console.WriteLine(numbers[3]); //writes out 5 - the new fourth item
Console.WriteLine(numbers.Count); //writes out 9 - there are nine elements now

numbers.RemoveAt(3); //removes the fourth element of the list
Console.WriteLine(numbers[0]); //writes out 2 - still the first item
Console.WriteLine(numbers[3]); //writes out 6 - the new fourth item
Console.WriteLine(numbers.Count); //writes out 8 - there are eight elements total
于 2013-01-04T12:12:01.820 に答える
0

リストではなくキューが必要なようです。

于 2013-01-04T12:08:58.697 に答える
0

これを試して:

level.Terrain.RemoveAt(0)
于 2013-01-04T12:09:06.077 に答える