typescript 如何声明 List<string> 类型的变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23193491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 01:14:13  来源:igfitidea点击:

How to declare a variable of type List<string>?

typescript

提问by user1673394

I am using TypeScript and having a C# class with a property of type List<string>. I need to have the same type of property in TypeScript.

我正在使用 TypeScript 并且有一个 C# 类的属性类型为List<string>。我需要在 TypeScript 中拥有相同类型的属性。

How can I declare a property in TypeScript class of type List<string>?

如何在类型为 TypeScript 的类中声明属性List<string>

回答by basarat

List<string>is something specific to C# and depends upon the Base class library (BCL) support in .NET.

List<string>是 C# 特有的,取决于 .NET 中的基类库 (BCL) 支持。

For TypeScript by default (without an external library like https://github.com/basarat/typescript-collections) you are limited to the built in JavaScript Array type. Here is a small sample to show its usage:

对于默认情况下的 TypeScript(没有像https://github.com/basarat/typescript-collections这样的外部库),您仅限于内置的 JavaScript 数组类型。下面是一个小示例来展示它的用法:

var foo:string[] = ['a','b']; 
foo.push('c');
console.log(foo) // [a,b,c]