草庐IT

bodyTemp

全部标签

go - 基于结构字段返回 slice 最小值的函数?

我有一个Go结构,例如:typepatientstruct{patientIDintageintbodyTempintnumberVaccinesintrecordIDint}如何编写一个函数,通过选择我感兴趣的字段返回patientslice中的最小值?我会这样调用它:someSlice:=[]patient{patient{...},...,...}fmt.Printf("Patientlowesttemp:%v",someSlice.GetMin(bodyTemp)谢谢! 最佳答案 因为已经写在评论中,你可以使用反射来完成,但