英文:
How do I dereference a pointer in Go?
问题
在Go语言中,有没有办法将*string
转换为string
?(或者,同样地,将任何*T
转换为T
?)
我在互联网上搜索了一下,并查阅了一些Go文档,但是我找不到相关信息,可能是我漏掉了。
英文:
In the Go language, is there any way to convert *string
to string
? (or, for that matter, any *T
to T
?)
I have looked on the internet and through some Go documentation, but I can't find it - may have missed it.
答案1
得分: 7
将*T
转换为T
,可以使用*
运算符:
func Dereference(strptr *string) string {
return *strptr
}
在继续学习这门语言之前,我强烈建议你先了解一下指针。它们是一种基本概念,没有它们的话,就无法高效地使用这门语言。
英文:
To turn a *T
into a T
, use the *
operator:
func Dereference(strptr *string) string {
return *strptr
}
I highly suggest you to read about pointers before proceeding with the language. They are a fundamental concept without which it is impossible to use the language efficiently.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论