سؤال

عندما اكتب:

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top