逐个读取二进制文件并转换?

Read binary file position by position and convert it?

我知道 VB 我们可以使用此代码读取二进制文件

    Function GetMonData()
            Dim Header(63) As Byte, Rows As Long, NoUse As Long
            Dim i As Long, j As Long, TmpStr As String

            Open "file.dat" For Binary As #1
                Get #1, , Header
                Get #1, , Rows
                Get #1, , NoUse       
            Close #1
    End Function

但是 c# 中的方法怎么样? 特别是 Get #1, , Header 我已经试过了

string strFilePath = @"C:\file.dat";
FileStream stream = new FileStream(strFilePath, FileMode.Open);
BinaryReader b = new BinaryReader(File.Open(strFilePath, FileMode.Open));

我只是混淆了获取数据 (63) byte for header,(4) byte for Rows,(4) byte for NoUse 在 VB 中我们可以使用 Get #1, , Header,那么 c# 呢?我需要寻找流?

提前致谢

即VB6/VBA代码。 VB.NET 仍然勉强地支持旧语法,以允许移植程序。但是您肯定必须将声明从 Long 更改为 Integer。

如果您需要像这样读取旧文件,那么最明显的方法就是利用 .NET 出色的语言互操作性并创建一个 VB.NET class 库您在 C# 项目中引用。到目前为止,确保代码兼容并且可以处理 Get() 的怪异语义的最佳方法。

否则你将不得不使用 BinaryReader.GetBytes() 来读取 Header,ReadInt32() 来获取其他的。