当前位置:网站首页>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))
}边栏推荐
- Go admin framework analysis (2-1)
- Basic concepts of database
- C语言的指针
- Not only products, FAW Toyota can give you "all-round" peace of mind
- Decipher Bishengyuan: is it tea that consumers buy, or is it IQ tax?
- 2022 latest MySQL interview questions
- Windows系统下C语言连接MySQL
- Shell uses arrays
- Computer shortcuts During sorting, fill in as needed
- Get the mobile number of QQ friends through exhaustive search
猜你喜欢

Leetcode hot topic Hot 100, to be updated
![In 2021, China's deposit balance continued to grow, and the balance of RMB and foreign currency deposits reached a record high [figure]](/img/23/652f596091dde97031a27bdbccdd0f.jpg)
In 2021, China's deposit balance continued to grow, and the balance of RMB and foreign currency deposits reached a record high [figure]

Promotion guide for large enterprises: material preparation, PPT writing and on-site defense

Summary of the most basic methods of numpy
![[leetcode] sum of two numbers - go language solution](/img/b8/d40cfe3efeedd816c5b81a1c939bd7.jpg)
[leetcode] sum of two numbers - go language solution

2022 latest MySQL interview questions

Based on Transformer's artificial neural network, the image of organic structure is transformed into molecular structure

Gold, silver and four interviews are necessary. The "brand new" assault on the real topic collection has stabilized Alibaba Tencent bytes

Niuke - real exercise-01

Phantom star VR product details 31: escape from the secret room
随机推荐
Learn upward management and four questioning skills to get twice the result with half the effort
Word thesis typesetting tutorial
100% troubleshooting and analysis of Alibaba cloud hard disk
Online keyboard key detection tool
C language pointer
养老年金险是理财产品吗?资金安全吗?
Based on Transformer's artificial neural network, the image of organic structure is transformed into molecular structure
For the first time in China, Tsinghua and other teams won the wsdm2022 only best paper award, and Hong Kong Chinese won the "time test Award"
2020-11-12 meter skipping
Decipher Bishengyuan: is it tea that consumers buy, or is it IQ tax?
In 2021, China's deposit balance continued to grow, and the balance of RMB and foreign currency deposits reached a record high [figure]
R语言使用fs包的file_access函数、file_exists函数、dir_exists函数、link_exists函数分别查看文件是否可以访问、文件是否存在、目录是否存在、超链接是否存在
Indexes, constraints and views in Oracle Database
Non local network: early human attempts to tame transformer in CV | CVPR 2018
After the uproar, is the yuan universe "cool"?
Clickhouse cluster installation has too many dry goods
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
阶乘求和
[North Asia data recovery] SQLSERVER database encrypted data recovery case sharing
利用并查集求最小生成树