Newbie Question: Quick way to generate binary checksum??

  • Thread starter Thread starter Damien Sawyer
  • Start date Start date
D

Damien Sawyer

Hi all,

Can someone please tell me if there's a standard .net framework function to
generate a binary checksum over a series of fields? For those familiar with
SQL server , I want to mimic the functionality of the binary_checksum()
function.

I guess that I want a 'hash code' over a collection of string objects.


Thanks very much in advance,



Damien Sawyer
 
Try just adding all your strings to an ArrayList and then calling the
GetHashCode method on the ArrayList.
 
Thanks Ray, I tried that but it didn't work...

Sub Main()

Dim ar1 As ArrayList = New ArrayList

ar1.Add("Hello")

ar1.Add("World")

Dim ar2 As ArrayList = New ArrayList

ar2.Add("Hello")

ar2.Add("World")

Console.WriteLine(ar1.GetHashCode) ' returned 4

Console.WriteLine(ar2.GetHashCode) ' returned 5



End Sub





However, this did work.... it was an interesting exercise... Thanks for your
help.







Module Module1

Sub Main()

Dim ar() As String = New String() {"This", "Is", "A", "Test"}

Dim ar2() As String = New String() {"This", "Is", "A", "Test"}

Dim ar3() As String = New String() {"This", "Is", "A", "Different", "Test"}

Console.WriteLine(arArrayHash.GetHashCode(ar)) ' 5969003

Console.WriteLine(arArrayHash.GetHashCode(ar2)) ' 5969003

Console.WriteLine(arArrayHash.GetHashCode(ar3)) ' -406042581

End Sub

End Module

Public Class arArrayHash

Shared Shadows Function GetHashCode(ByVal ar() As String) As Integer

Dim iResult As Int32

iResult = ar(0).GetHashCode

For Each o As String In ar

If Array.IndexOf(ar, o) <> 0 Then

iResult = iResult Xor o.GetHashCode

End If

Next

Return iResult

End Function

End Class
 
Sorry, my bad... I should not have fired from the hip like that.

I thought that the hashcode of an arraylist would change if the arraylist
changed. It does not. My bad here.

I also thought you were looking for a way to judge if a collections of
strings had changed, hence why I said what I did (even though it was wrong).
 
Back
Top