How to declare an array in a struct in golang | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

How to declare an array in a struct in golang

I want a array in the struct ,how to do it? Okay,i tried .. type Model struct{ list []string } Is it correct way of declaring?

22nd May 2021, 6:05 AM
OfcourseitsRohit
OfcourseitsRohit - avatar
1 Resposta
+ 1
Lucifer Correct. But if you want to create a object of this struct use this below declarationā†“ func main(){ obj:=Modal{[]string{"item1", "item2"}} }
22nd May 2021, 7:17 AM
Ėœā€*Ā°ā€¢.Ėœā€*Ā°ā€¢ Mohan 333 ā€¢Ā°*ā€Ėœ.ā€¢Ā°*ā€Ėœ
Ėœā€*Ā°ā€¢.Ėœā€*Ā°ā€¢ Mohan 333 ā€¢Ā°*ā€Ėœ.ā€¢Ā°*ā€Ėœ - avatar