C# 如何更新列表中的值<;矢量2>;列表

C# 如何更新列表中的值<;矢量2>;列表,c#,visual-studio-2010,windows-phone-7,windows-phone,C#,Visual Studio 2010,Windows Phone 7,Windows Phone,我刚开始学习Windows Phone编程 我有一个这样定义的列表 private List<Vector2> _terrain; public List<Vector2> Terrain { get { return _terrain; } } 假设我在这个列表中有50个元素。我想做的是,我想删除列表中的第一项,然后将第二项移到第一位,第三项移到第二位,等等。我想做的是生成随机的“东西”。有了这个,我打算让他们看起来像是在移动。谢谢你的帮助 听起来你想

我刚开始学习Windows Phone编程

我有一个这样定义的列表

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

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

听起来你想要的是队列而不是列表。

试试这个:

level.Terrain.RemoveAt(0)
List
类试图为项目列表结构提供抽象。 因此,每当从列表中删除一个项目时,它就会消失,并且列表会自动压缩。例如,如果我有:

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
列表编号=新列表();
对于(int i=0;i<10;i++)
{
number.Add(i+1);//将数字1添加到10
}
Console.WriteLine(数字[0])//写出1-第一项
Console.WriteLine(数字[3])//写出4-第四项
控制台。写入线(数字。计数)//写出10个-有10个元素
数字。删除(0)//删除列表的第一个元素
Console.WriteLine(数字[0])//写出2-新的第一项
Console.WriteLine(数字[3])//写出5-新的第四项
控制台。写入线(数字。计数)//写出9-现在有九个元素
数字。删除(3)//删除列表的第四个元素
Console.WriteLine(数字[0])//写出2-仍然是第一项
Console.WriteLine(数字[3])//写出6-新的第四项
控制台。写入线(数字。计数)//写出8个-共有8个元素
使用通用队列

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

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