当前位置:网站首页>GO语言-type关键字
GO语言-type关键字
2022-06-21 15:32:00 【一边学习一边哭】
type定义简单类型
语法
type关键字 类型名 typetype myint int
type mystring string
func main() {
var i1 myint = 1
i2 := 1
fmt.Printf("类型比较:\ti1的类型:%T\ti2的类型:%T\n", i1, i2)
var s1 mystring = "hello"
s2 := "hello"
fmt.Printf("类型比较:\ts1的类型:%T\ts2的类型:%T\n", s1, s2)
}
此时的i1 i2;s1 s2的类型是不一样的,不可以将i1 i2或s1 s2相互赋值 。
类型别名
语法
type关键字 类型别名 = typetype myint = int
func main() {
var i1 myint = 1
i2 := 1
fmt.Printf("类型比较:\ti1的类型:%T\ti2的类型:%T\n", i1, i2)
fmt.Println(i1 + i2)
}

type定义函数类型
type myfun func(int, int) string
func fun1() myfun {
fun := func(a, b int) string {
s := strconv.Itoa(a) + strconv.Itoa(b)
return s
}
return fun
}
func main() {
testfun := fun1()
fmt.Println(testfun(100, 200))
}边栏推荐
- Write static multi data source code and do scheduled tasks to realize database data synchronization
- JS interview question: regular expression, to be updated
- What is a good product for children's serious illness insurance? Please recommend it to a 3-year-old child
- Rk3399 platform development series explanation (network debugging) 7.32. What is network routing?
- Shell uses arrays
- Go admin framework analysis (2-1)
- Redis introduction and Practice (with source code)
- Algorithm question: interview question 32 - I. print binary tree from top to bottom (title + idea + code + comments) sequence traversal time and space 1ms to beat 97.84% of users once AC
- Best practice | how to use Tencent cloud micro build to develop enterprise portal applications from 0 to 1
- C语言的指针
猜你喜欢

P24 de noise

Metric win computer application

Basic concepts of database

Alibaba cloud energy consumption treasure will be released soon to help SMEs' green upgrading and participate in the carbon neutral trillion market

Phantom star VR product details 34: Happy pitching

C language to achieve three chess (detailed explanation)
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures!
![[Yugong series] February 2022 wechat applet -app Debug JSON configuration attribute](/img/33/103a207dc085c431557981b3c9a1d5.jpg)
[Yugong series] February 2022 wechat applet -app Debug JSON configuration attribute

Niuke - real exercise-01

HSV color model and color component range in opencv
随机推荐
[go] goroutine pool
C language to achieve three chess (detailed explanation)
JS interview question: regular expression, to be updated
What is the server room
Integration of sparkstreaming and sparksql
AAAI 2022 | sasa: rethinking point cloud sampling in 3D object detection
2020-11-12 meter skipping
Fundamentals of C language 13: file input / output
Clickhouse client connection
Best practice | how to use Tencent cloud micro build to develop enterprise portal applications from 0 to 1
Kubeneters installation encountered gcr The IO image warehouse cannot be pulled
Why do you want to be naked with a router
Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]
Judge password strength - Optimization
Rk3399 platform development series explanation (network debugging) 7.32. What is network routing?
Factorial summation
57 common mistakes in golang development
Non local network: early human attempts to tame transformer in CV | CVPR 2018
How is the network connected
我不太想在網上開戶,網上股票開戶安全嗎