我怎么知道C#中BinaryReader的当前偏移量?

Jos*_*Son 7 c# binaryreader

我有以下来源:

public static void DisplayValues()
{
    float aspectRatio;
    string tempDirectory;
    int autoSaveTime;
    bool showStatusBar;

    if (File.Exists(fileName))
    {
        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            aspectRatio = reader.ReadSingle();
            tempDirectory = reader.ReadString();
    ------------------------------------------------> I want to know current offset.
            autoSaveTime = reader.ReadInt32();
            showStatusBar = reader.ReadBoolean();
        }

        Console.WriteLine("Aspect ratio set to: " + aspectRatio);
        Console.WriteLine("Temp directory is: " + tempDirectory);
        Console.WriteLine("Auto save time set to: " + autoSaveTime);
        Console.WriteLine("Show status bar: " + showStatusBar);
    }
}
Run Code Online (Sandbox Code Playgroud)

我必须找出BinaryReader的当前偏移量.

Sam*_*uel 9

您可以通过获取基础流

var stream = reader.BaseStream;
Run Code Online (Sandbox Code Playgroud)

并获得该职位

stream.Position
Run Code Online (Sandbox Code Playgroud)