当前位置:网站首页>Rewrite string() method in go language
Rewrite string() method in go language
2022-06-26 07:54:00 【weixin_ thirty-eight million one hundred and fifty-five thousan】
Go In language String Method
stay go If overridden String Method , That's calling fmt.Println Will automatically execute String Method
stay fmt Interface is defined in 


stay go If static constants are defined in , And used iota when , It is best to set a for static constants String Method
type State int
const (
Running State = iota
Stopped
Rebooting
Terminated
)
func (s State) String() string {
switch s {
case Running:
return “Running”
case Stopped:
return “Stopped”
case Rebooting:
return “Rebooting”
case Terminated:
return “Terminated”
default:
return “Unknown”
}
}
func main(){
state := Running
fmt.Println(“state”, state) // Not added String When the method is used . Entered as 0 Output as after adding "Running"
}
边栏推荐
- C#/. Net phase VI 01C Foundation_ 02:vs2019 basic operations, excluding code files, smart tips, data types, differences between float and double, and differences between string and string
- What are the key points of turnover box management in warehouse management
- Leetcode topic [array] -11- containers with the most rainwater
- Opencv鼠标事件+界面交互之绘制矩形多边形选取感兴趣区域ROI
- Here is the command to display the disk space usage. Go ahead and pay attention to more wonderful things!
- Uniapp scrolling load (one page, multiple lists)
- Redis (5) -- Talking about compressed list
- Orderly arrangement
- Wifi-802.11 2.4G band 5g band channel frequency allocation table
- Google Earth Engine(GEE) 01-中输入提示快捷键Ctrl+space无法使用的问题
猜你喜欢

How to define a digital factory and what is the relationship with smart factory and industry 4.0

Junit

Chapter 4 (functions and preprocessing)

PCB miscellaneous mail

Can the warehouse management system help enterprises reduce storage costs

My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?
![[NLP] vector retrieval model landing: Bottleneck and solution!](/img/c4/784534e5504dfee1c989d19255c31b.jpg)
[NLP] vector retrieval model landing: Bottleneck and solution!

ReW_ p

What is the five levels of cultivation of MES management system

Chapter 5 (array)
随机推荐
Two models of OSPF planning: double tower Raider and dog tooth crisscross
Chapter VI (pointer)
You can command Siri without making a sound! The Chinese team of Cornell University developed the silent language recognition necklace. Chinese and English are OK
Double linked list -- tail interpolation construction (C language)
我想造SQL数据(存储结构)
Webrtc has become the official standard of W3C and IETF, and mobile terminal development
45. jumping game II dynamic planning DP
Chapter 4 (functions and preprocessing)
Google Earth Engine(GEE) 01-中输入提示快捷键Ctrl+space无法使用的问题
ECE 9203/9023 analysis
[SystemVerilog basics] post_ Randomize function record
2021 project improvement
C#/. Net phase VI 01C Foundation_ 02:vs2019 basic operations, excluding code files, smart tips, data types, differences between float and double, and differences between string and string
Solve psycopg2 NotSupportedError: PQconninfo not available in libpq < 9.3
Apache InLong毕业成为顶级项目,具备百万亿级数据流处理能力!
Can the warehouse management system help enterprises reduce storage costs
The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer
Record the dependent installation problems encountered in building the web assets when developing pgadmin
What if the service in Nacos cannot be deleted?
Nine hours, nine people and nine doors (01 backpack deformation) - Niuke