I am using TypeScript and have a C# class with a property of type List<string>
. I need to have the same type of property in TypeScript.
How can I declare a property in TypeScript class of type List<string>
?
The type syntax for declaring a variable in TypeScript is to include a colon (:) after the variable name, followed by its type. Just as in JavaScript, we use the var keyword to declare a variable. Declare its type and value in one statement.
To add string values to a list in C#, use the Add() method.
List<String>[] = ... Represents a variable declared to contain Datatype of List of Strings which is also an Array.
In TypeScript, an array is an ordered list of values. An array can store a mixed type of values. To declare an array of a specific type, you use the let arr: type[] syntax.
List<string>
is something specific to C# and depends upon the Base class library (BCL) support in .NET.
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:
var foo:string[] = ['a','b'];
foo.push('c');
console.log(foo) // [a,b,c]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With