Skip to content

Commit 1e4e3c0

Browse files
authored
Update xor2.cs (#4574)
Cleaner version of Equals. Avoids hiding the execution break in an if(){} and also avoids the unnecessary ! on (obj is Point).
1 parent c6788aa commit 1e4e3c0

File tree

1 file changed

+9
-4
lines changed
  • samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs

1 file changed

+9
-4
lines changed

samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ public Point(int x, int y)
1414

1515
public override bool Equals(Object obj)
1616
{
17-
if (!(obj is Point)) return false;
18-
19-
Point p = (Point) obj;
20-
return x == p.x & y == p.y;
17+
if (obj is Point)
18+
{
19+
Point p = (Point) obj;
20+
return x == p.x & y == p.y;
21+
}
22+
else
23+
{
24+
return false;
25+
}
2126
}
2227

2328
public override int GetHashCode()

0 commit comments

Comments
 (0)