Comparing two arrays.
What doesn’t work
int[] a = new int[2]{1,2}; int[] b = new int[2]{1,2}; if (a.Equals(b)) { // No match. The Array objects differ although they contain the same value. } b = a; if (a.Equals(b)) { // Match, the Array objects are the same. }
What does work
Strangely enough the Array function does not contain a compare function.
To compare two buffers use the following code
i int i; for (int i=0; i < first.Length; i++) { if (first[i] != second[i]) { return false; } }
Note this code is optimized by the compiler which detects 0 < Length loops.