<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Using Tuples for Overriding Equality and GetHashCode	</title>
	<atom:link href="https://intellitect.com/blog/overidingobjectusingtuple/feed/" rel="self" type="application/rss+xml" />
	<link>https://intellitect.com/blog/overidingobjectusingtuple/</link>
	<description>Complex Software Development - Simplified</description>
	<lastBuildDate>Wed, 18 May 2022 18:01:27 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Steven Rothwell		</title>
		<link>https://intellitect.com/blog/overidingobjectusingtuple/#comment-385711</link>

		<dc:creator><![CDATA[Steven Rothwell]]></dc:creator>
		<pubDate>Tue, 29 Jun 2021 12:44:27 +0000</pubDate>
		<guid isPermaLink="false">https://intellitect.com/?p=33129#comment-385711</guid>

					<description><![CDATA[I really like this implementation.  Was using it as a guide when writing my own.  I found that == and != operators will throw null reference error if lhs is null.  Since default implementation of == and != operators does not bomb when null, I think this should be accounted for.  Similarly said for Equals(Arc arc) if arc is null.  In my code, I accounted for this by utilizing a static GetHashCode(Arc arc) method.

public static Int32 GetHashCode(Arc arc)
{
            if (arc is null)
                return 0;

            return (arc.Radius, arc.StartAngle, arc.SweepAngle).GetHashCode();
}

This allows you to simplify both Equals methods, operator methods, and non-static GetHashCode() to all call this static GetHashCode(Arc arc).]]></description>
			<content:encoded><![CDATA[<p>I really like this implementation.  Was using it as a guide when writing my own.  I found that == and != operators will throw null reference error if lhs is null.  Since default implementation of == and != operators does not bomb when null, I think this should be accounted for.  Similarly said for Equals(Arc arc) if arc is null.  In my code, I accounted for this by utilizing a static GetHashCode(Arc arc) method.</p>
<p>public static Int32 GetHashCode(Arc arc)<br />
{<br />
            if (arc is null)<br />
                return 0;</p>
<p>            return (arc.Radius, arc.StartAngle, arc.SweepAngle).GetHashCode();<br />
}</p>
<p>This allows you to simplify both Equals methods, operator methods, and non-static GetHashCode() to all call this static GetHashCode(Arc arc).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Eric Robishaw		</title>
		<link>https://intellitect.com/blog/overidingobjectusingtuple/#comment-385638</link>

		<dc:creator><![CDATA[Eric Robishaw]]></dc:creator>
		<pubDate>Tue, 22 Jun 2021 23:41:34 +0000</pubDate>
		<guid isPermaLink="false">https://intellitect.com/?p=33129#comment-385638</guid>

					<description><![CDATA[Be very careful, however. If you have 8+ items in the Tuple, the Tuple&#039;s GetHashCode() value get&#039;s wonky, and appears to only use the last 8 items (not the first 8)
(1, 10, &quot;&quot;, 2, 42, &quot;ABC&quot;, 723, 1000652, 4).GetHashCode() ==
(5, 10, &quot;&quot;, 2, 42, &quot;ABC&quot;, 723, 1000652, 4).GetHashCode()

(1, 10, &quot;&quot;, 2, 42, &quot;ABC&quot;, 723, 1000652).GetHashCode().Dump() !=
(5, 10, &quot;&quot;, 2, 42, &quot;ABC&quot;, 723, 1000652).GetHashCode().Dump()

(5, 10, &quot;&quot;, 2, 42, &quot;ABC&quot;, 723, 1000652, 2).GetHashCode().Dump() !=
(5, 10, &quot;&quot;, 2, 42, &quot;ABC&quot;, 723, 1000652, 3).GetHashCode().Dump();]]></description>
			<content:encoded><![CDATA[<p>Be very careful, however. If you have 8+ items in the Tuple, the Tuple&#8217;s GetHashCode() value get&#8217;s wonky, and appears to only use the last 8 items (not the first 8)<br />
(1, 10, &#8220;&#8221;, 2, 42, &#8220;ABC&#8221;, 723, 1000652, 4).GetHashCode() ==<br />
(5, 10, &#8220;&#8221;, 2, 42, &#8220;ABC&#8221;, 723, 1000652, 4).GetHashCode()</p>
<p>(1, 10, &#8220;&#8221;, 2, 42, &#8220;ABC&#8221;, 723, 1000652).GetHashCode().Dump() !=<br />
(5, 10, &#8220;&#8221;, 2, 42, &#8220;ABC&#8221;, 723, 1000652).GetHashCode().Dump()</p>
<p>(5, 10, &#8220;&#8221;, 2, 42, &#8220;ABC&#8221;, 723, 1000652, 2).GetHashCode().Dump() !=<br />
(5, 10, &#8220;&#8221;, 2, 42, &#8220;ABC&#8221;, 723, 1000652, 3).GetHashCode().Dump();</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kevin Bost		</title>
		<link>https://intellitect.com/blog/overidingobjectusingtuple/#comment-378621</link>

		<dc:creator><![CDATA[Kevin Bost]]></dc:creator>
		<pubDate>Fri, 15 Nov 2019 17:47:59 +0000</pubDate>
		<guid isPermaLink="false">https://intellitect.com/?p=33129#comment-378621</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/overidingobjectusingtuple/#comment-376744&quot;&gt;PAUL G MILLER&lt;/a&gt;.

When you do (Radius, StartAngle, SweetAngle) it creates a System.ValueTuple and invokes the GetHashCode function of it. ValueTuple&#039;s GetHashCode method will combine the hash codes of each of its members to produce a file hash code. 

 https://source.dot.net/#System.Private.CoreLib/shared/System/ValueTuple.cs,763]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/overidingobjectusingtuple/#comment-376744">PAUL G MILLER</a>.</p>
<p>When you do (Radius, StartAngle, SweetAngle) it creates a System.ValueTuple and invokes the GetHashCode function of it. ValueTuple&#8217;s GetHashCode method will combine the hash codes of each of its members to produce a file hash code. </p>
<p> <a href="https://source.dot.net/#System.Private.CoreLib/shared/System/ValueTuple.cs,763" rel="nofollow ugc">https://source.dot.net/#System.Private.CoreLib/shared/System/ValueTuple.cs,763</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: PAUL G MILLER		</title>
		<link>https://intellitect.com/blog/overidingobjectusingtuple/#comment-376744</link>

		<dc:creator><![CDATA[PAUL G MILLER]]></dc:creator>
		<pubDate>Fri, 23 Aug 2019 22:27:00 +0000</pubDate>
		<guid isPermaLink="false">https://intellitect.com/?p=33129#comment-376744</guid>

					<description><![CDATA[public override int GetHashCode() =&#062; return (Radius, StartAngle, SweepAngle).GetHashCode();
will just return Radius.GetHashCode() so that&#039;s probably not what you want. 

https://github.com/dotnet/coreclr/blob/4aa65f077778c7c05211825f98684aae9c52caaf/src/System.Private.CoreLib/shared/System/Tuple.cs]]></description>
			<content:encoded><![CDATA[<p>public override int GetHashCode() =&gt; return (Radius, StartAngle, SweepAngle).GetHashCode();<br />
will just return Radius.GetHashCode() so that&#8217;s probably not what you want. </p>
<p><a href="https://github.com/dotnet/coreclr/blob/4aa65f077778c7c05211825f98684aae9c52caaf/src/System.Private.CoreLib/shared/System/Tuple.cs" rel="nofollow ugc">https://github.com/dotnet/coreclr/blob/4aa65f077778c7c05211825f98684aae9c52caaf/src/System.Private.CoreLib/shared/System/Tuple.cs</a></p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
