Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I declare a variable of type List<string>? [closed]

Tags:

typescript

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>?

like image 227
user1673394 Avatar asked Apr 21 '14 08:04

user1673394


People also ask

How do you declare a variable in a TypeScript?

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.

How do I make a list of strings in C#?

To add string values to a list in C#, use the Add() method.

What does list string mean in Java?

List<String>[] = ... Represents a variable declared to contain Datatype of List of Strings which is also an Array.

How do you define a list type in TypeScript?

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.


1 Answers

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] 
like image 105
basarat Avatar answered Oct 23 '22 14:10

basarat