Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3340124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:34:17+00:00 2026-05-18T00:34:17+00:00

I was searching for a BinaryReader.Skip function, while I came across this feature request

  • 0

I was searching for a BinaryReader.Skip function, while I came across this feature request on msdn.
He said you can provide your own BinaryReader.Skip() function, by using this.

Only looking at this code, I’m wondering why he chose this way to skip a certain amount of bytes:

    for (int i = 0, i < count; i++) {
        reader.ReadByte();
    }

Is there a difference between that and:

reader.ReadBytes(count);

Even if it’s just a small optimalisation, I’d like to undestand. Because now it doesnt make sense to me why you would use the for loop.

public void Skip(this BinaryReader reader, int count) {
    if (reader.BaseStream.CanSeek) { 
        reader.BaseStream.Seek(count, SeekOffset.Current); 
    }
    else {
        for (int i = 0, i < count; i++) {
            reader.ReadByte();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:34:18+00:00Added an answer on May 18, 2026 at 12:34 am

    No, there is no difference. EDIT: Assuming that the stream has enough byes

    The ReadByte method simply forwards to the underlying Stream’s ReadByte method.

    The ReadBytes method calls the underlying stream’s Read until it reads the required number of bytes.
    It’s defined like this:

    public virtual byte[] ReadBytes(int count) {
        if (count < 0) throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); 
        Contract.Ensures(Contract.Result<byte[]>() != null); 
        Contract.Ensures(Contract.Result<byte[]>().Length <= Contract.OldValue(count));
        Contract.EndContractBlock(); 
        if (m_stream==null) __Error.FileNotOpen();
    
        byte[] result = new byte[count];
    
        int numRead = 0;
        do { 
            int n = m_stream.Read(result, numRead, count); 
            if (n == 0)
                break; 
            numRead += n;
            count -= n;
        } while (count > 0);
    
        if (numRead != result.Length) {
            // Trim array.  This should happen on EOF & possibly net streams. 
            byte[] copy = new byte[numRead]; 
            Buffer.InternalBlockCopy(result, 0, copy, 0, numRead);
            result = copy; 
        }
    
        return result;
    } 
    

    For most streams, ReadBytes will probably be faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In searching I came across ASP.NET MVC page/subpage routing and the wildcard was somewhat
Searching on Google reveals x2 code snippets. The first result is to this code
While searching the interweb for a solution for my VB.net problems I often find
When searching in SharePoint the results are returned to a page called OSSSearchResults.aspx. This
Searching did not find a similar question, so: How can POST data used by
Searching here I found that this question was already asked , but I think
Searching on Stackoverflow and writing this question has taken more time than the change
When searching (across files) or finding (within files), if you have regular expressions enabled
Some searching through Google (and my own experience) shows that in PHP you can't
Searching Stackoverflow on Google I get this result: Inspecting the HTML source of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.