CSharpTest.Net
Compare Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > BinaryComparer Class : Compare Method

ar1
ar2

Glossary Item Box

Compares the contents of the byte arrays and returns the result.

Syntax

Visual Basic (Declaration) 
Public Shared Function Compare( _
   ByVal ar1() As Byte, _
   ByVal ar2() As Byte _
) As Integer
C# 
public static int Compare( 
   byte[] ar1,
   byte[] ar2
)

Parameters

ar1
ar2

Example

Library/Library.Test/TestBinaryComparer.cs

C#Copy Code
List<byte[]> all = new List<byte[]>();

all.Add(null);
all.Add(Guid.Empty.ToByteArray());
for (int i = 0; i < 1000; i++)
    all.Add(Guid.NewGuid().ToByteArray());

all.Sort(new BinaryComparer());

byte[] last = null;
Assert.IsNull(all[0]);
all.RemoveAt(0);

foreach (byte[] entry in all)
{
    if(last != null)
        Assert.IsTrue(StringComparer.Ordinal.Compare(Convert.ToBase64String(last), Convert.ToBase64String(entry)) < 0);
    Assert.IsTrue(BinaryComparer.Compare(last, entry) < 0);
}
VB.NETCopy Code
Dim all As New List(Of Byte())()

all.Add(Nothing)
all.Add(Guid.Empty.ToByteArray())
Dim i As Integer = 0
While i < 1000
    all.Add(Guid.NewGuid().ToByteArray())
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

all.Sort(New BinaryComparer())

Dim last As Byte() = Nothing
Assert.IsNull(all(0))
all.RemoveAt(0)

For Each entry As Byte() In all
    If last <> Nothing Then
        Assert.IsTrue(StringComparer.Ordinal.Compare(Convert.ToBase64String(last), Convert.ToBase64String(entry)) < 0)
    End If
    Assert.IsTrue(BinaryComparer.Compare(last, entry) < 0)
Next

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys