我是VB.NET的新手,我正在尝试在Visual Studio 2013中实现一些东西,以计算字节数组的CRC-32字节。我遇到过各种各样的例子,一些是VB.NET,另一些是C#。尽管如此,我还没有成功地让他们工作甚至测试它们。
例如,考虑来自" Mangus"的特定代码。我在这个网站上找到了。我将其复制并粘贴到Windows表单模板中,我收到此错误:
错误BC30456:'转储'不是UInteger'
的成员
我道歉,因为我可能会做一些非常愚蠢的事情,但我感谢任何帮助或提示。
Private Sub Main()
Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")).Dump()
End Sub
Public Class Crc32
Shared table As UInteger()
Shared Sub New()
Dim poly As UInteger = &Hedb88320UI
table = New UInteger(255) {}
Dim temp As UInteger = 0
For i As UInteger = 0 To table.Length - 1
temp = i
For j As Integer = 8 To 1 Step -1
If (temp And 1) = 1 Then
temp = CUInt((temp >> 1) Xor poly)
Else
temp >>= 1
End If
Next
table(i) = temp
Next
End Sub
Public Shared Function ComputeChecksum(bytes As Byte()) As UInteger
Dim crc As UInteger = &HffffffffUI
For i As Integer = 0 To bytes.Length - 1
Dim index As Byte = CByte(((crc) And &Hff) Xor bytes(i))
crc = CUInt((crc >> 8) Xor table(index))
Next
Return Not crc
End Function
End Class
答案 0 :(得分:0)
如果您从其他地方复制了此内容,那么我猜测Dump
是一种扩展方法,可以执行Debug.Print
尝试替换它:
Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")).Dump()
有了这个:
Debug.Print(Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")))