我抓我的頭關於這個問題,我不明白爲什麼會發生以下情況它的方式:比較時,沒有鍵字段的VB.NET匿名類型與C#匿名類型有什麼不同?
'//VB.NET
Dim product1 = New With {.Name = "paperclips", .Price = 1.29}
Dim product2 = New With {.Name = "paperclips", .Price = 1.29}
'compare product1 and product2 and you get false returned.
Dim product3 = New With {Key .Name = "paperclips", Key .Price = 1.29}
Dim product4 = New With {Key .Name = "paperclips", Key .Price = 1.29}
'compare product3 and product4 and you get true returned.
'//C#
var product5 = new {Name = "paperclips", Price = 1.29};
var product6 = new {Name = "paperclips", Price = 1.29};
//compare products 5 and 6 and you get true.
什麼用的產品1和2,使他們不能表現得像產品5和6發生了什麼?
也許它是由等於/ ==差異引起的..你如何比較它們?如果字段相同,C#在anynomus類中的equals會返回true。 –