Afn*_*oom 1 vb.net arrays compare bytearray equals
好的,我想做的是比较vb.net中的2字节数组.我试过这些代码:
If Byte.ReferenceEquals(bytearrayone, bytearraytwo) Then
MsgBox("Yes", MsgBoxStyle.Information)
Else
MsgBox("No", MsgBoxStyle.Critical)
End If
Run Code Online (Sandbox Code Playgroud)
和
If Array.ReferenceEquals(bytearrayone, bytearraytwo) Then
MsgBox("Yes", MsgBoxStyle.Information)
Else
MsgBox("No", MsgBoxStyle.Critical)
End If
Run Code Online (Sandbox Code Playgroud)
两个字节数组都是相同的,一个数组从资源中获取一个字节的字节,另一个数组从计算机获取.出于测试目的,我在两个阵列中使用了相同的文件,但根据提供的代码,我得到的只是否.两者都有相同的长度,我通过它们两个循环,在相同的点都有相同的字节.那有什么不对?我应该使用什么代码?请帮我.
使用SequenceEqual
Dim foo() As Byte = {1, 2, 3, 4}
Dim barT() As Byte = {1, 2, 3, 4}
Dim barF() As Byte = {1, 2, 3, 5}
Dim fooEqbarT As Boolean = foo.SequenceEqual(barT)
Dim fooEqbarF As Boolean = foo.SequenceEqual(barF)
Debug.WriteLine(fooEqbarT)
Debug.WriteLine(fooEqbarF)
Run Code Online (Sandbox Code Playgroud)
比较两个小文件
Dim path1 As String = "pathnameoffirstfile"
Dim path2 As String = "pathnameofsecondfile"
Dim foo() As Byte = IO.File.ReadAllBytes(path1)
Dim bar() As Byte = IO.File.ReadAllBytes(path2)
If foo.SequenceEqual(bar) Then
'identical
Else
'different
End If
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7989 次 |
最近记录: |