執行緒(Thread) 複習作業系統(Operating System)中的對於執行緒(thread)的解釋: 執行緒(thread)是OS能夠進
Maps A map maps key to value. Golang provides map data structure which implements hashtable. 1. Creating a Maps The zero value of a map is nil. A nil map has no keys, nor can keys be added. Method 1: like array // nil map var m map[keyTpye]valueType Note: 如果使用此方法來create map,還需要
Array 1. Creating an Array The type [n]T is an array of n values of type T. The expression var a [10]int An array’s length is part of its type, so arrays cannot be resized. But Go provides a convenient way of working with array. 2. Array initialize a := [6]int{2, 3, 5, 7, 11, 13} // or a := []int{2, 3, 5, 7, 11, 13} Slices A slice is
Structs (Structures) A struct or structure is a collection of fields. 1. Defining a struct Using struct keyword to create a new structure type. type StructName struct { field1 fieldType1 field2 fieldType2 ... } Example: type Vertex struct { X int Y int } 2. Accessing Struct Fields (Members) Struct fields are accessed using a dot. v := Vertrx{1, 2} v.X = 4 fmt.Println(v.X) // 4 Pointers to Structs 1.
For Go has only one looping construct, the foor loop for <init state>; <condition>; <post state> sum := 0 for i := 0; i < 10; i++ { sum += i } Go的for看起來跟C或Java中的依樣,但是沒有 (),但{}是必要的,如上