مشكلة غريبة عند محاولة قراءة البيانات
-
18-09-2019 - |
سؤال
عندما اكتب:
var tagType = _reader.ReadByte();
while (tagType != 8)
{
var skip = ReadNext3Bytes() + 11;
_reader.BaseStream.Position += skip;
tagType = _reader.ReadByte();
}
... تعمل، ولكن عندما أكتب:
var tagType = _reader.ReadByte();
while (tagType != 8)
{
_reader.BaseStream.Position += ReadNext3Bytes() + 11;
tagType = _reader.ReadByte();
}
... لا يعمل، ولا أستطيع أن أفهم لماذا - أحصل على نتائج غير متوقعة. هيريس ReadNext3Bytes
طريقة:
private long ReadNext3Bytes()
{
try
{
return Math.Abs((_reader.ReadByte() & 0xFF) * 256 * 256 + (_reader.ReadByte() & 0xFF)
* 256 + (_reader.ReadByte() & 0xFF));
}
catch
{
return 0;
}
}
لماذا هذا، وكيف يمكنني إصلاحه؟
شكرا.
المحلول
يحدث ذلك منذ ذلك الحين موضع يتم تغييرها خلال ReadByte. اتصل، ما تراه يشبه هذه الحالة:
int position = 1;
position += (position = 2) + 3;
Assert.AreEqual(6, position);
لا تنتمي إلى StackOverflow