Skip to content

Commit ef7a7ff

Browse files
committed
Adds create a slices eg
1 parent 9794342 commit ef7a7ff

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
func main() {
4+
5+
/**
6+
* Blank [] will declare a slices.
7+
* If you provide size like [5] will declare an array.
8+
*/
9+
var employee []string
10+
11+
/**
12+
* Initialize a slices with type, length and capacity.
13+
* length is required field.
14+
*
15+
* make([]string, length, [capacity])
16+
*/
17+
employee = make([]string, 3)
18+
19+
employee[0] = "Ashwin"
20+
employee[1] = "Kumar"
21+
employee[2] = "Saju"
22+
// employee[3] = "Ajay" // This will throw an error `out of range`
23+
}

0 commit comments

Comments
 (0)