开发者

C# equivalent to AS3 Vector?

Is there an equivalent object type for Actionscript's Vector in C#? If not, wha开发者_Python百科t is would generally be used?


From the ActionScript® 3.0 Reference for the Adobe® Flash® Platform:

The Vector class lets you access and manipulate a vector — an array whose elements all have the same data type.

The equivalent class in .NET is the generic List<T> Class.

From MSDN:

Represents a strongly typed list of objects that can be accessed by index.

The element's type is designated by the generic type parameter T. So, for example, a "Vector with base type String" Vector.<String> in Flash would be a "List of X" List<string> in C#.

Example:

var dinosaurs = new List<string>();

dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");

foreach (var dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}


That would be the List<T> in .NET.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜