Question

I have source below:

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);
    }
}

I have to find out current offset of BinaryReader.

Was it helpful?

Solution

You can obtain the underlying stream by

var stream = reader.BaseStream;

and get the position by

stream.Position

OTHER TIPS

BinaryReader br=null;
/ * init, read, ...*/
long pos=br.BaseStream.Position;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top