golang中的byte、rune对应的基础类型

golang中存在丰富的类型,其中一部分类型如byte、rune等是基于底层的整形等基础类型实现的,熟悉类型对应的基础类型能够帮助我们了解一些coding中的小技巧,可以基于类型的基础类型直接使用。
首先了解一下一些内建类型对应的基础类型,这些都可以在源码中builtin.go中找到:

// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8

// rune is an alias for int32 and is equivalent to int32 in all ways. It is
// used, by convention, to distinguish character values from integer values.
type rune = int32

// iota is a predeclared identifier representing the untyped integer ordinal
// number of the current const specification in a (usually parenthesized)
// const declaration. It is zero-indexed.
const iota = 0 // Untyped int.

如下一些小技巧:

s:="abc"
cs := make([]int, 128)
for _, c := range s {
   cs[c] += 1
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值