簡體   English   中英

List.Count重置為零

[英]List.Count resets to zero

我想創建一個包含11個條目的列表,但List.Count在此代碼后重置為零。

列表中沒有添加任何條目。 怎么了?

List<Animation> animations = new List<Animation>();

animations[0] = new Animation(new List<Rectangle>(10), 
                                     Content.Load<Texture2D>("pictures"), 
                                     TimeSpan.FromSeconds(2), 
                                     Animation.Animationsablaeufe.vorrück);
List<Animation> animations = new List<Animation>(); // count should be 0

animations.Add(new Animation(...)); // count should be 1
animations.Add(new Animation(...)); // count should be 2

// etc...

您還可以使用以下表示法,它等效於:

List<Animation> animations = new List<Animation>
{
   new Animation(...),
   new Animation(...),
   new Animation(...),
   new Animation(...),
   ...
   new Animation(...)
};
List<Animation> Animations = new List<Animation>();

Animations.Add(new Animation);

Animations.Count();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM