1package main 2 3import ( 4 "fmt" 5) 6 7type Student struct { 8 id int 9 name string 10} 11 12func main() { 13 //比较 14 s1 := Student{1, "yy"} 15 s2 := Student{2, "yang"} 16 s3 := Student{1, "yy"} 17 fmt.Println(s1 == s2) //false 18 fmt.Println(s1 == s3) //true 19 //赋值 20 var s4 Student 21 s4 = s1 22 fmt.Println(s4) //{1 yy} 23}
两个结构体可以使用 == 或 != 运算符进行比较,但不支持 > 或 <。
同类型的两个结构体变量可以相互赋值。