Skip to content

Commit c955a71

Browse files
committed
use pattern matching in Equals(object) methods
1 parent 96b933f commit c955a71

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/LinqStatistics/Bin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public override int GetHashCode()
104104
/// <returns></returns>
105105
public override bool Equals(object obj)
106106
{
107-
if (obj is Bin)
107+
if (obj is Bin b)
108108
{
109-
this.Equals((Bin)obj);
109+
this.Equals(b);
110110
}
111111

112112
return false;

src/LinqStatistics/ItemCount.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public int Count
8282
/// <returns>True if obj is a Bin{T} and Value and Count are equal</returns>
8383
public override bool Equals(object obj)
8484
{
85-
if (obj is ItemCount<T>)
85+
if (obj is ItemCount<T> c)
8686
{
87-
return this.Equals((ItemCount<T>)obj);
87+
return this.Equals(c);
8888
}
8989

9090
return false;

src/LinqStatistics/LeastSquares.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ public static implicit operator Func<double, double>(LeastSquares ls)
117117
/// <returns>True if obj is a LeastSquares and has equal m and b values</returns>
118118
public override bool Equals(object obj)
119119
{
120-
if (obj is LeastSquares)
120+
if (obj is LeastSquares ls)
121121
{
122-
return this == (LeastSquares)obj;
122+
return this == ls;
123123
}
124124

125125
return false;

src/LinqStatistics/Range.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ internal Range(T min, T max, bool noThrow)
123123
/// </returns>
124124
public override bool Equals(object obj)
125125
{
126-
if (obj is Range<T>)
126+
if (obj is Range<T> r)
127127
{
128-
return this == (Range<T>)obj;
128+
return this == r;
129129
}
130130

131131
return false;
@@ -155,9 +155,9 @@ public int CompareTo(object obj)
155155
return 1;
156156
}
157157

158-
if (obj is Range<T>)
158+
if (obj is Range<T> r)
159159
{
160-
return this.CompareTo((Range<T>)obj);
160+
return this.CompareTo(r);
161161
}
162162

163163
throw new ArgumentException("Comparand must be of type Range<T>");

0 commit comments

Comments
 (0)