몇 가지 포럼에서 이미이 질문을했지만 위의 코드를 C#에서 Visual Basic으로 변환 할 수없는 이유에 대해서는 설명하지 않았습니다.VB.NET에서 GetStableHash 메서드를 구현하는 방법
코드는 실제로이 포럼의 C#으로 작성되었습니다. (the source)
static public int GetStableHash(string s)
{
uint hash = 0;
// if you care this can be done much faster with unsafe
// using fixed char* reinterpreted as a byte*
foreach (byte b in System.Text.Encoding.Unicode.GetBytes(s))
{
hash += b;
hash += (hash << 10);
hash ^= (hash >> 6);
}
// final avalanche
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
// helpfully we only want positive integer < MUST_BE_LESS_THAN
// so simple truncate cast is ok if not perfect
return (int)(hash % MUST_BE_LESS_THAN);
}
그래서, 코드가한다고는 VB.NET
Const MUST_BE_LESS_THAN As Integer = 100000000
Function GetStableHash(ByVal s As String) As Integer
Dim hash As UInteger = 0
For Each b as Byte In System.Text.Encoding.Unicode.GetBytes(s)
hash += b
hash += (hash << 10)
hash = hash Xor (hash >> 6)
Next
hash += (hash << 3)
hash = hash Xor (hash >> 11)
hash += (hash << 15)
Return Int(hash Mod MUST_BE_LESS_THAN)
End Function
바로 것 같다에서 그런 일이 될,하지만 그것은 작동하지 않습니다. VB.NET에서는 "hash + = (해쉬 < < 10)"이
VB.net에서 파일/파일의 일부분에 대한 오버플로 검사를 변경할 방법이 없습니까? C#'unchecked' 키워드와 비슷합니까? – CodesInChaos
아니요, 해당 언어로 된 키워드가 없습니다. 언어 구문에 의해 오버플로 검사가 가정됩니다. 그래서 바이트에 int를 할당하기 위해 캐스트하지 않아도됩니다. –