Reputation: 169
Is there an equivalent object type for Actionscript's Vector in C#? If not, what is would generally be used?
Upvotes: 2
Views: 703
Reputation: 217283
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);
}
Upvotes: 7