当前位置:网站首页>Go language -type keyword
Go language -type keyword
2022-06-21 15:38:00 【Crying while learning】
type Define simple types
grammar
type keyword Type name typetype myint int
type mystring string
func main() {
var i1 myint = 1
i2 := 1
fmt.Printf(" Type comparison :\ti1 The type of :%T\ti2 The type of :%T\n", i1, i2)
var s1 mystring = "hello"
s2 := "hello"
fmt.Printf(" Type comparison :\ts1 The type of :%T\ts2 The type of :%T\n", s1, s2)
}
At this time i1 i2;s1 s2 There are different types of , You can't put i1 i2 or s1 s2 Assign values to each other .
Type the alias
grammar
type keyword Type the alias = typetype myint = int
func main() {
var i1 myint = 1
i2 := 1
fmt.Printf(" Type comparison :\ti1 The type of :%T\ti2 The type of :%T\n", i1, i2)
fmt.Println(i1 + i2)
}

type Define function types
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))
}边栏推荐
- C language pointer
- Somme factorielle
- Phantom star VR product details 34: Happy pitching
- Telnet batch test (I): pit between telnet graceful stop and firewall
- 57 common mistakes in golang development
- AAAI 2022 | sasa: rethinking point cloud sampling in 3D object detection
- Phy336 Computational Physics
- C language selection type supplement
- 2022awe opened in March, and Hisense conference tablet was shortlisted for the review of EPLAN Award
- Not only products, FAW Toyota can give you "all-round" peace of mind
猜你喜欢

Operator Tour (I)

Phantom star VR product details 34: Happy pitching

Browser evaluation: a free, simple and magical super browser - xiangtian browser

GO语言-指针

2022 Hunan top eight (Safety Officer) simulated test question bank and answers

Someone is storing credit card data - how do they do it- Somebody is storing credit card data - how are they doing it?

Not only products, FAW Toyota can give you "all-round" peace of mind

GO语言-方法

对Integer进行等值比较时踩到的一个坑
![Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]](/img/86/26a9319734854e7ad0e10d9ac2e8eb.jpg)
Analysis on the scale and market structure of China's bill financing industry in 2020 [figure]
随机推荐
我的Debug之路1.0
Phantom star VR product details 31: escape from the secret room
养老年金险是理财产品吗?资金安全吗?
Talk about MySQL's locking rule "hard hitting MySQL series 15"
原生JS路由,iframe框架
[leetcode] sum of two numbers - go language solution
Gee Registration Guide
Brain: machine learning reveals two different neuroanatomical subtypes of schizophrenia
Finding minimum spanning tree by using union search set
Several common implementation methods of mock interface test
57 common mistakes in golang development
Kubeneters installation encountered gcr The IO image warehouse cannot be pulled
[Yugong series] February 2022 wechat applet -app Networktimeout of JSON configuration attribute
阶乘求和
Basic concepts of database
階乘求和
Kitchen appliance giant employee data was leaked during the attack, and Iran's national radio was attacked by malware | February 22 global network security hotspot
Kubeneters' CNI network plug-in installation Kube ovn
[Yugong series] February 2022 wechat applet -app Debug JSON configuration attribute
Best practice | how to use Tencent cloud micro build to develop enterprise portal applications from 0 to 1