Whats is the difference between Array<string>
and string[]
?
var jobs: Array<string> = ['IBM', 'Microsoft', 'Google']; var jobs: string[] = ['Apple', 'Dell', 'HP'];
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.
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.
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.
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.
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