<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Comparing byte arrays in C#, or at least, trying to &#8230;</title>
	<atom:link href="http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/</link>
	<description>Enter the Tatrix</description>
	<lastBuildDate>Wed, 10 Mar 2010 19:33:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: La billeterie &#187; Blog Archive &#187; c# comparaison de tableaux</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14283</link>
		<dc:creator>La billeterie &#187; Blog Archive &#187; c# comparaison de tableaux</dc:creator>
		<pubDate>Mon, 18 Jan 2010 12:06:29 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14283</guid>
		<description>[...] fourni la solution propre recherchée avec c# 3.5 : http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/ Publi&#233; dans General &#124; Commentaires [...]</description>
		<content:encoded><![CDATA[<p>[...] fourni la solution propre recherchée avec c# 3.5 : <a href="http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/" rel="nofollow">http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/</a> Publi&eacute; dans General | Commentaires [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn Slayden</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14136</link>
		<dc:creator>Glenn Slayden</dc:creator>
		<pubDate>Thu, 20 Aug 2009 05:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14136</guid>
		<description>The angle brackets for the generic argument T were stripped off my posting by your blog. It belongs after the function name &quot;ValueCompare&quot; and also after the EqualityComparer.</description>
		<content:encoded><![CDATA[<p>The angle brackets for the generic argument T were stripped off my posting by your blog. It belongs after the function name &#8220;ValueCompare&#8221; and also after the EqualityComparer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn Slayden</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14135</link>
		<dc:creator>Glenn Slayden</dc:creator>
		<pubDate>Thu, 20 Aug 2009 05:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14135</guid>
		<description>public static bool ValueCompare(this T[] a, T[] b) where T: struct
{
   if (a.Length != b.Length)
      return false;
   EqualityComparer q = EqualityComparer.Default;
   for (int i = 0; i &lt; a.Length; i++)
      if (!q.Equals(a[i],b[i]))
         return false;
   return true;
}</description>
		<content:encoded><![CDATA[<p>public static bool ValueCompare(this T[] a, T[] b) where T: struct<br />
{<br />
   if (a.Length != b.Length)<br />
      return false;<br />
   EqualityComparer q = EqualityComparer.Default;<br />
   for (int i = 0; i &lt; a.Length; i++)<br />
      if (!q.Equals(a[i],b[i]))<br />
         return false;<br />
   return true;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kees C. Bakker</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14129</link>
		<dc:creator>Kees C. Bakker</dc:creator>
		<pubDate>Tue, 11 Aug 2009 09:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-14129</guid>
		<description>If you don&#039;t want to create your own class, just use this helper method somewhere.

private static bool CompareByteArrays(byte[] array1, byte[] array2)
{
	if (array1.Length != array2.Length)
		return false;

	for (int i = 0; i &lt; array1.Length; i++)
		if (array1[i] != array2[i])
			return false;

	return true;
}

Good luck!

=D Kees</description>
		<content:encoded><![CDATA[<p>If you don&#8217;t want to create your own class, just use this helper method somewhere.</p>
<p>private static bool CompareByteArrays(byte[] array1, byte[] array2)<br />
{<br />
	if (array1.Length != array2.Length)<br />
		return false;</p>
<p>	for (int i = 0; i &lt; array1.Length; i++)<br />
		if (array1[i] != array2[i])<br />
			return false;</p>
<p>	return true;<br />
}</p>
<p>Good luck!</p>
<p>=D Kees</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13918</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Fri, 03 Jul 2009 00:18:05 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13918</guid>
		<description>Microsoft is correct in their explanation. I think as you become more experienced with OO languages it will make more sense. 


However, I wanted to explain why some of the suggestions here should not be used. 

1: Convert.ToBase64String(array1)==Convert.ToBase64String(array2)
The problems with this are as follows:
  a: You are always getting the worst possible performance out of this. Without first checking the lengths of the arrays to be sure they are equal then you will always end up processing both arrays entirely.
  b: Terrible runtime performance. You are iterating across all of array1 and array2 to convert them to strings, then iterating across both resulting strings to check equality. This will do twice as much work as just iterating through them and comparing the array byte values. Just because a method is provided by the runtime does not make it any faster than doing it manually(in most cases). 
  c: Terrible memory use. Although the strings are only used for a moment, there is a price to pay for allocating them. 

I would write more but now I am tired of all of this. 
-Tim</description>
		<content:encoded><![CDATA[<p>Microsoft is correct in their explanation. I think as you become more experienced with OO languages it will make more sense. </p>
<p>However, I wanted to explain why some of the suggestions here should not be used. </p>
<p>1: Convert.ToBase64String(array1)==Convert.ToBase64String(array2)<br />
The problems with this are as follows:<br />
  a: You are always getting the worst possible performance out of this. Without first checking the lengths of the arrays to be sure they are equal then you will always end up processing both arrays entirely.<br />
  b: Terrible runtime performance. You are iterating across all of array1 and array2 to convert them to strings, then iterating across both resulting strings to check equality. This will do twice as much work as just iterating through them and comparing the array byte values. Just because a method is provided by the runtime does not make it any faster than doing it manually(in most cases).<br />
  c: Terrible memory use. Although the strings are only used for a moment, there is a price to pay for allocating them. </p>
<p>I would write more but now I am tired of all of this.<br />
-Tim</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hemant Kumar</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13778</link>
		<dc:creator>Hemant Kumar</dc:creator>
		<pubDate>Wed, 15 Apr 2009 05:02:23 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13778</guid>
		<description>Hi,
This technique is gud for me to compare to byte[] arrays.

Convert.ToBase64String(array1)==Convert.ToBase64String(array2)

Thanks!!</description>
		<content:encoded><![CDATA[<p>Hi,<br />
This technique is gud for me to compare to byte[] arrays.</p>
<p>Convert.ToBase64String(array1)==Convert.ToBase64String(array2)</p>
<p>Thanks!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13755</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Mon, 23 Feb 2009 20:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13755</guid>
		<description>There are two things wrong with your method:

1. You can&#039;t have both static and override modifiers on the same method - I presume this was a typo;

2. Your method only works for vectors; multi-dimensional arrays would take a lot more effort.</description>
		<content:encoded><![CDATA[<p>There are two things wrong with your method:</p>
<p>1. You can&#8217;t have both static and override modifiers on the same method &#8211; I presume this was a typo;</p>
<p>2. Your method only works for vectors; multi-dimensional arrays would take a lot more effort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Comparing Byte Arrays in C# and more specifically using the .NET 3.5 Framework - Andrew Rea</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13747</link>
		<dc:creator>Comparing Byte Arrays in C# and more specifically using the .NET 3.5 Framework - Andrew Rea</dc:creator>
		<pubDate>Fri, 20 Feb 2009 11:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13747</guid>
		<description>[...] http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/" rel="nofollow">http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jojan</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13729</link>
		<dc:creator>jojan</dc:creator>
		<pubDate>Thu, 29 Jan 2009 18:05:58 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13729</guid>
		<description>If you are not using Linq
Pleas try

Convert.ToBase64String(array1)==Convert.ToBase64String(array2)</description>
		<content:encoded><![CDATA[<p>If you are not using Linq<br />
Pleas try</p>
<p>Convert.ToBase64String(array1)==Convert.ToBase64String(array2)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tatham Oddie</title>
		<link>http://blog.tatham.oddie.com.au/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13260</link>
		<dc:creator>Tatham Oddie</dc:creator>
		<pubDate>Tue, 04 Nov 2008 22:12:16 +0000</pubDate>
		<guid isPermaLink="false">http://tatham.wordpress.com/2008/07/01/comparing-byte-arrays-in-c-or-at-least-trying-to/#comment-13260</guid>
		<description>Great tip Richard! I&#039;ll add it to the post.</description>
		<content:encoded><![CDATA[<p>Great tip Richard! I&#8217;ll add it to the post.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
