Could anyone point out to me the difference between ulong (C#) and
UInt64/ULong (VB.Net)? I was under the impression that both are same. Below
C# code works fine for a particular value of 'data' (string length 36) and
initial hash value '0' whereas VB.Net code throws an exception in the 8th
iteration, saying the data is either too large or too small for a Uint64. I
am using VB.Net/C# 2005. Am I missing anything here?
C# Code:
=======
static private ulong GetULongHash( string data, ulong hash )
{
hash += ( hash << 13 ) + (ulong)data.Len gth;
for (int i = 0; i < data.Length; i++)
{
hash += (hash << 17) + data[i];
}
return hash;
}
VB.Net Code:
==========
Private Shared Function GetUInt64Hash(B yVal data As String, ByVal hash As
System.UInt64) As System.UInt64
hash += (hash << 13) + CType(data.Leng th, System.UInt64)
Dim i As Integer = 0
While i < data.Length
hash += (hash << 17) + Asc(data(i))
System.Math.Min (System.Threadi ng.Interlocked. Increment(i), i - 1)
End While
Return hash
End Function
UInt64/ULong (VB.Net)? I was under the impression that both are same. Below
C# code works fine for a particular value of 'data' (string length 36) and
initial hash value '0' whereas VB.Net code throws an exception in the 8th
iteration, saying the data is either too large or too small for a Uint64. I
am using VB.Net/C# 2005. Am I missing anything here?
C# Code:
=======
static private ulong GetULongHash( string data, ulong hash )
{
hash += ( hash << 13 ) + (ulong)data.Len gth;
for (int i = 0; i < data.Length; i++)
{
hash += (hash << 17) + data[i];
}
return hash;
}
VB.Net Code:
==========
Private Shared Function GetUInt64Hash(B yVal data As String, ByVal hash As
System.UInt64) As System.UInt64
hash += (hash << 13) + CType(data.Leng th, System.UInt64)
Dim i As Integer = 0
While i < data.Length
hash += (hash << 17) + Asc(data(i))
System.Math.Min (System.Threadi ng.Interlocked. Increment(i), i - 1)
End While
Return hash
End Function
Comment