Quick actions

cmd+k|ctrl+k

Navigation

Languages

Basic types / Type casting / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:12:06Z

Updated

2019-03-26T10:12:06Z

package main

func main() {
	// you can cast between numbers i.e. integers of various sizes and floating point numbers
	var i1 int32 = 3
	var i2 int = int(i1) // we must explicitly cast from int32 to int
	var f float64 = float64(i1)

	s := "string"
	// we can cast between string and []byte and vice-versa
	// note that unless optimizted by the compiler, this involves allocation
	var d []byte = []byte(s)

	_, _, _ = i2, f, d // silence compiler error about unused variables
}
INFO