0

我刚开始学习 Windows Phone 编程。

我有一个这样定义的列表,

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

在此之下,我用一些像这样的向量填充列表,

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

假设我在这个列表中有 50 个元素。我想要做的是,我想删除这个列表中的第一项,然后将第二项移动到第一位,第三到第二等等等等。我想要做的是我正在生成随机的“事物” . 有了这个,我打算让它们看起来像在移动。谢谢您的帮助!

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

使用通用队列

Queue<Vector2> testQueue= new Queue<Vector2>();

另请查看此链接以获取有关通用队列的更多信息

于 2013-01-04T12:16:32.147 回答
0

sounds like you want a Queue instead of a List.

于 2013-01-04T12:08:58.697 回答
0

Try this:

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