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

Glossary Item Box

Dictionary comparer for comparing arrays of bytes by value equality

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class BinaryComparer 
C# 
public sealed class BinaryComparer 

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

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Crypto.BinaryComparer

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys