Clarified and fixed some horrific errors (#22355)
* Clarified the sentence about zero indexing and that any data type can be stored in an array * Added spacing between elements * Fixed declaration format `new nameOfArray[numberOfElements](vals)` is definitely not a thing it should be `new dataType [numberOfElements](vals)` * Added shorthand definition * Removed claim that you are storing an array in another array by assigning an alias to it
This commit is contained in:
committed by
Manish Giri
parent
c2027c19a7
commit
af0c94f6e9
@ -8,9 +8,9 @@ An array is used to store a collection of data of the same type. This can be use
|
||||
|
||||
## Rules of Arrays
|
||||
|
||||
Arrays start from zero. The first element of an array is 0, the second element is 1, the third element 2, and so on.
|
||||
Arrays start from zero. That is to say that the first element of an array is indexed as 0, the second element is 1, the third element 2, and so on.
|
||||
|
||||
Arrays must be of the same data type. You can use any data type in an array (e.g. int, double, float, string, enum)
|
||||
Arrays must be of the same data type. You can use any data type in an array (e.g. int, double, float, string, enum, List, People, etc.)
|
||||
|
||||
A new Array must first be declared and initialised before it can be called and accessed.
|
||||
|
||||
@ -36,7 +36,7 @@ Code above will assign the value of 50 directly into element [2]
|
||||
|
||||
You can assign multiple values at once while declaring the array using the format below:
|
||||
|
||||
`dataType [] nameOfArray = {5,17,19,92};`
|
||||
`dataType [] nameOfArray = {5, 17, 19, 92};`
|
||||
|
||||
The above code will assign the value of 5 into element [0], 17 into element [1], 19 into element [2] and 92 into element [3].
|
||||
|
||||
@ -70,12 +70,11 @@ The above code will assign the value of 5 into element [0], 17 into element [1],
|
||||
|
||||
You can declare, initilise and assign values in the array all at once by using the format below:
|
||||
|
||||
`dataType [] nameOfArray = new nameOfArray[numberOfElements] {value1,value2,value3,value4};`
|
||||
`dataType [] nameOfArray = new dataType[numberOfElements] {value1, value2, value3, value4};`
|
||||
|
||||
You can store an array directly into another array by using the format below:
|
||||
or simply:
|
||||
|
||||
`int [] nameOfArray = new nameOfArray[4] {2,9,56,1280};`
|
||||
`int [] nameOfSecondArray = nameOfArray;`
|
||||
`var nameOfArray = new dataType {value1, value2, value3, value4};`
|
||||
|
||||
## Advantages
|
||||
|
||||
|
Reference in New Issue
Block a user