在Go语言中,有没有用于逐个比较两个结构数组的内置方法?

huangapple go评论72阅读模式
英文:

Inbuilt method for element wise comparison of 2 struct arrays in Go?

问题

我有一个具有以下结构的结构体:

//Number 表示要添加的新数字的结构体
type Number struct {
    Country   string `json:"country"`
    Number    string `json:"number"`
    CreatedAt string `json:"created_at"`
}

我从 REST 调用中获取到一个包含此结构体的响应数组,我需要进行逐个元素的比较。是否有内置的方法可以实现相同的功能,或者有更高效的方法来实现,而不是使用 for 循环和迭代元素?

英文:

I have a struct with the below structure,

//Number A struct that represents a new number to be addeded
type Number struct {
	Country   string `json:"country"`
	Number    string `json:"number"`
	CreatedAt string `json:"created_at"`
}

and I a getting a response array of this struct from the REST call and I need to do an element-wise comparison. Is there any inbuilt method to do the same or more efficient way to do it instead of using a for loop and iterating through the elements?

答案1

得分: 1

有没有内置的方法来完成相同的操作,或者有没有比使用for循环和迭代元素更高效的方法?

类型为Number的值可以直接使用==进行比较。

英文:

> Is there any inbuilt method to do the same or more efficient way to do it instead of using a for loop and iterating through the elements?

Values of type Number can be compared with == directly.

huangapple
  • 本文由 发表于 2022年2月11日 20:10:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/71079880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定