How to find out the current BinaryReader offset in C #?

I have a 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 need to find the current BinaryReader offset.

+6
source share
2 answers

You can get the base stream

 var stream = reader.BaseStream; 

and get a position

 stream.Position 
+7
source
 BinaryReader br=null; / * init, read, ...*/ long pos=br.BaseStream.Position; 
+1
source

All Articles