.Net?泄???????????
?????Sweet-Tang ???????[ 2017/6/28 10:45:43 ] ??????????????????? .NET
????????????????
??????.Net????校??????????????????????????些??????????????????????????????
????1 float num1 = 2.000000f;
????2 float num2 = 2.000001f;
????3
????4 Console.WriteLine(num1 == num2);
???????????????????????????????????????????????????????????尾????????????????????谐????????????????????True??
????????????????????????????????????????????矛?????????????????2?????????????????????????????????????float???????娲�??????效???????????????????????????????????????????????????????????
????1 float num1 = 0.7f;
????2 float num2 = 0.6f + 0.1f;
????3
????4 Console.WriteLine(num2);
????5 Console.WriteLine(num1 == num2);
???????????????????????0.6??0.1?????????????????????0.7?????????????谐????????????????????False?????????False???????????????????0.7???????????????????????????谐????????????????娲�???????????????????num2?????String???????????????????????0.7??????num2???????????0.7??
?????????????味???卸????????????????????????.Net????????????????????????????????????????????????????????????????????????????????????????????????小???????????????????锟�?????????????????????小????????????????????????
??????stackoverflow???????????????????????慰???https://stackoverflow.com/questions/6598179/the-right-way-to-compare-a-system-double-to-0-a-number-int??
?????????????????????矛??
????????????????????????????????械???????????????????????????????????????????????????????????????????写??????????????????Bug??
?????????????????????????????????????谢???Animal?????????????Dog?????????
????1 public class Animal
????2 {
????3
????4 }
????5
????6 public class Dog : Animal
????7 {
????8
????9 }
????????????????Animal????????????????????Animal??????????????????IEquatable<Animal>????????????????Equals()????????Animal?????????????????
1 public class Animal : IEquatable<animal>
????2 {
????3 public virtual bool Equals(Animal other)
????4 {
????5 throw new NotImplementedException();
????6 }
????7 }
??????????????Dog?????????????????????Dog????????????????????IEquatable<Dog>??????味????????????Equals()????????Dog?????????????????
????1 public class Dog : Animal?? IEquatable<Dog>
????2 {
????3 public virtual bool Equals(Dog other)
????4 {
????5 throw new NotImplementedException();
????6 }
????7 }
??????????????????????????????????OOP?????校???????????Dog?????Animal???Equals()???????????榉�????Dog??Equals()??????Animal???Equals()?????????????????????????????写????Animal???Equals()????????????????????????????????Equals???????????????????
?????????????????写Object????Equals???????梅??????????Object??????????????????味??????????????????????????????写????????????????????????????
???????
????C#????????????????????????????味???????????????????????"=="????????????校?
?????????????????????卸??.Net???????????????????????????????????写????????????????????????????
???????????????????????????????????????????????????????
???????????????????????????????????????
??????

???路???
??????????????????
2023/3/23 14:23:39???写?貌??????????
2023/3/22 16:17:39????????????????????些??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???路???????路
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11