Saturday, April 27, 2024
HomeGolangCan somebody kindly ELI5 the distinction between utilizing slice of pointers and...

Can somebody kindly ELI5 the distinction between utilizing slice of pointers and slice of structs? – Getting Assist


I do know there are tons of assets however coming from C# background, studying about all these simply makes me extra confused. For basic objective, which one is preferable and what are the professionals/cons of every method.

Slice of struct pointers being handed as parameter or returned from a operate:

func getAllAnimals() []*Animal  {
}

func printAllAnimals(animals []*Animal) {
}

V/S

Slice of struct being handed as parameter or returned from a operate:

func getAllAnimals() []Animal  {
}

func printAllAnimals(animals []Animal) {
}

it’s best to write like this in golang
func getAllAnimals() (Animal,error) {
var(
x Animal
err error
)

return x,nil
}

information,err := getAllAnimals()
if err != nil {
}

sort or paste code right here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments