C# 为什么不是';此内存映射文件读取是否正确?

C# 为什么不是';此内存映射文件读取是否正确?,c#,memory-mapped-files,C#,Memory Mapped Files,我有种感觉我做错了什么,但我不知道是什么 这是我的密码: long offset = 0x009694E3; long length = 0x02; byte[] bytes = new byte[length]; // Create the memory-mapped file. using (var mmf = MemoryMappedFile.CreateFromFile(strFil

我有种感觉我做错了什么,但我不知道是什么

这是我的密码:

        long offset = 0x009694E3;
        long length = 0x02;
        byte[] bytes = new byte[length];

        // Create the memory-mapped file.
        using (var mmf =
            MemoryMappedFile.CreateFromFile(strFileName, FileMode.Open, "ISO"))
        {
            // Create a random access view, from the 256th megabyte (the offset)
            // to the 768th megabyte (the offset plus length).
            using (var accessor = mmf.CreateViewAccessor(offset, length))
            {
                // Make changes to the view.
                for (long i = 0; i < length; i++)
                {
                    bytes[i] = accessor.ReadByte(i);
                    dialogEdit.Text = bytes[i].ToString();
                }
            }
        }
long offset=0x009694E3;
长长度=0x02;
字节[]字节=新字节[长度];
//创建内存映射文件。
使用(var-mmf)=
MemoryMappedFile.CreateFromFile(strFileName,FileMode.Open,“ISO”))
{
//从256MB(偏移量)创建随机访问视图
//到768MB(偏移量加长度)。
使用(var accessor=mmf.CreateViewAccessor(偏移量,长度))
{
//对视图进行更改。
用于(长i=0;i
当我加载一个文件时,上面偏移量处的文本是0x22 0x44(“ASCII中的D”),而文本框的输出是“68”

我想我误解了字节的工作原理,但我不完全确定


非常感谢您的帮助!

在文本框中,您可以在第二个循环中将值34(0x22)改写为值68(0x44)


程序按编程方式运行。内存映射文件的幸运转义。

所以…0x22 0x44是两个字节。哪个是字节[0]处的字节?此外,字节上的ToString方法将返回一个数字,而不是ASCII字符。其中需要进行编码转换。