From 6dbdee5f669d4e784a79d37968fa695044d4e4bd Mon Sep 17 00:00:00 2001 From: JaredKreft Date: Sat, 25 Jul 2020 07:02:36 -0500 Subject: [PATCH 1/3] Update xor2.cs Cleaner version of Equals. Avoids hiding the execution break in an if(){} and also avoids the unnecessary ! on (obj is Point). --- .../system.object.gethashcode/cs/xor2.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs index 408eef2d4f4..ef1e4eece69 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs @@ -14,10 +14,15 @@ public Point(int x, int y) public override bool Equals(Object obj) { - if (!(obj is Point)) return false; - - Point p = (Point) obj; - return x == p.x & y == p.y; + if(obj is Point) + { + Point p = (Point) obj; + return x == p.x & y == p.y; + } + else + { + return false; + } } public override int GetHashCode() From 6b693df131f9d62dac7dca2eebba3e7ef905983b Mon Sep 17 00:00:00 2001 From: JaredKreft Date: Mon, 3 Aug 2020 14:30:23 -0500 Subject: [PATCH 2/3] Update samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- .../system.object.gethashcode/cs/xor2.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs index ef1e4eece69..cfa0c6a3bbf 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs @@ -14,7 +14,8 @@ public Point(int x, int y) public override bool Equals(Object obj) { - if(obj is Point) + if (obj is Point) + { Point p = (Point) obj; return x == p.x & y == p.y; From 2fa3e685b5fc6578ef251c0d5cf75104259f3ca5 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 3 Aug 2020 15:45:27 -0700 Subject: [PATCH 3/3] Remove empty line --- .../VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs index cfa0c6a3bbf..531b37784e1 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.gethashcode/cs/xor2.cs @@ -15,7 +15,6 @@ public Point(int x, int y) public override bool Equals(Object obj) { if (obj is Point) - { Point p = (Point) obj; return x == p.x & y == p.y;