简体   繁体   English

C#相当于AS3 Vector?

[英]C# equivalent to AS3 Vector?

Is there an equivalent object type for Actionscript's Vector in C#? C# 中的 Actionscript 向量是否有等效的 object 类型? If not, what is would generally be used?如果没有,一般会使用什么?

From the ActionScript® 3.0 Reference for the Adobe® Flash® Platform :来自Adobe® Flash® 平台的 ActionScript® 3.0 参考

The Vector class lets you access and manipulate a vector — an array whose elements all have the same data type.向量 class 允许您访问和操作向量 — 一个其元素都具有相同数据类型的数组。

The equivalent class in .NET is the generic List<T> Class . .NET 中的等效 class 是通用List<T> Class

From MSDN :来自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 .元素的类型由泛型类型参数T指定。 So, for example, a "Vector with base type String" Vector.<String> in Flash would be a "List of X" List<string> in C#.因此,例如,Flash 中的“具有基本类型字符串的向量” Vector.<String>将是 C# 中的“X 列表” List<string>

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.那将是 .NET 中的List<T>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM