what I wanted to make is a if statement which checks if the variable which has a offset in it is equal to the base stream length and if it is, it will break.
here is what I have:
//open.FileName is Test.txt which doesn't have the number 123 (aka "7B")
user_input = "123";
BinaryReader br = new BinaryReader(File.OpenRead(open.FileName));
for (int i = 0; i <= br.BaseStream.Length; i++)
{
if (i == br.BaseStream.Length) //for some reason this doesn't work. why?
{
br.Close();
operation_Info.Text = operation_Fail;
break;
}
br.BaseStream.Position = i;
string Locate = br.ReadInt32().ToString();
if (Locate == user_input)
{
br.Close();
operation_Info.Text = operation_Success;
break;
}
}
For some reason it ignores the if
and tries to check for 123 again but gives the error System.IO.EndOfStreamException: 'Unable to read beyond the end of the stream.'
sins its already at the end of the file. why doesnt the if
work?