Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference Array<string> and string[]?

Tags:

typescript

Whats is the difference between Array<string> and string[]?

var jobs: Array<string> = ['IBM', 'Microsoft', 'Google']; var jobs: string[]      = ['Apple', 'Dell', 'HP']; 
like image 734
Sajith Mantharath Avatar asked Jul 07 '16 07:07

Sajith Mantharath


People also ask

What is this string []?

String[] is an array of Strings. Therefore a container of many variables of String data type. For example: String[] strArray = new String[2]; str[0] = "Hello"; str[1] = "World"; String str = "Hello World"; Follow this answer to receive notifications.

What's the difference between String [] and string?

Essentially, there is no difference between string and String (capital S) in C#. String (capital S) is a class in the . NET framework in the System namespace. The fully qualified name is System.

What is Array & string?

An array is a collection of the same type variable. Whereas a string is a sequence of Unicode characters or array of characters. Therefore arrays of strings is an array of arrays of characters. Here, string array and arrays of strings both are same term.


1 Answers

There's no difference between the two, it's the same.

It says this in the docs:

Array types can be written in one of two ways. In the first, you use the type of the elements followed by [] to denote an array of that element type:

let list: number[] = [1, 2, 3]; 

The second way uses a generic array type, Array:

let list: Array<number> = [1, 2, 3]; 

You do need to use the Array<T> form when you want to extend it for example:

class MyArray extends Array<string> { ... } 

but you can't use the other form for this.

like image 126
Nitzan Tomer Avatar answered Sep 23 '22 06:09

Nitzan Tomer