diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IPPacketInformation.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IPPacketInformation.cs
index 89d1081228978b..e4df5776b93e1b 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IPPacketInformation.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IPPacketInformation.cs
@@ -42,10 +42,8 @@ public int Interface
return !(packetInformation1 == packetInformation2);
}
- public override bool Equals(object comparand)
- {
- return comparand is IPPacketInformation && this == (IPPacketInformation)comparand;
- }
+ public override bool Equals(object comparand) =>
+ comparand is IPPacketInformation other && this == other;
public override int GetHashCode()
{
diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/MulticastOption.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/MulticastOption.cs
index 161c41249d286e..5f413cf06cfc0b 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/MulticastOption.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/MulticastOption.cs
@@ -67,7 +67,7 @@ public IPAddress Group
}
set
{
- _group = value;
+ _group = value ?? throw new ArgumentNullException(nameof(value));
}
}
@@ -150,12 +150,7 @@ public IPAddress Group
}
set
{
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- _group = value;
+ _group = value ?? throw new ArgumentNullException(nameof(value));
}
}
diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs
index 2e94a735933e08..02da108c787ef7 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs
@@ -69,15 +69,8 @@ public override int GetHashCode()
///
/// The object to compare with this instance
/// true if obj is an instance of and equals the value of the instance; otherwise, false
- public override bool Equals(object obj)
- {
- if (!(obj is UdpReceiveResult))
- {
- return false;
- }
-
- return Equals((UdpReceiveResult)obj);
- }
+ public override bool Equals(object obj) =>
+ obj is UdpReceiveResult other && Equals(other);
///
/// Returns a value that indicates whether this instance is equal to a specified object
diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/MulticastOptionTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/MulticastOptionTest.cs
index 6b712b21026ae3..456a2268e6c479 100644
--- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/MulticastOptionTest.cs
+++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/MulticastOptionTest.cs
@@ -26,8 +26,7 @@ public void MulticastOption_Group_Roundtrips()
var option = new MulticastOption(IPAddress.Any);
Assert.Same(IPAddress.Any, option.Group);
- option.Group = null;
- Assert.Null(option.Group);
+ AssertExtensions.Throws("value", () => option.Group = null);
option.Group = IPAddress.Broadcast;
Assert.Same(IPAddress.Broadcast, option.Group);