Share via

Duplicate Byte

OSVBNET 1,401 Reputation points
2022-08-05T02:39:34.043+00:00

Hello experts,
I'm not familiar with byte arrays, anyhow will need to load and hold a fie as byte:

Public MyFileAsByte As Byte() = Nothing
Dim MyBR As BinaryReader = Nothing
Try
MyBR = New BinaryReader(File.OpenRead("D:\file.ext"))
Dim MyFI As New FileInfo("D:\file.ext")
MyFileAsByte = MyBR.ReadBytes(Convert.ToInt32(MyFI.Length))
Finally
If Not MyBR Is Nothing Then MyBR.Close()
End Try

Now each time I need to access MyFileAsByte, I have to make a copy of it, and pass the copy to some functions (because they might alter the passed byte)
So how do you make an exact copy of MyFileAsByte now? (with no more access to the original file ie "D:\file.ext"
Without altering the original byte (MyFileAsByte)?
Thanks :)

Developer technologies | VB
0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2022-08-05T07:58:54.107+00:00

Try this:

Dim MyCopy As Byte() = MyFileAsByte.ToArray

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.