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 6188561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:15:14+00:00 2026-05-24T02:15:14+00:00

In this example from MS , you’ll notice that after we read a byte

  • 0

In this example from MS, you’ll notice that after we read a byte from memory stream, it goes into an int which must then be converted to byte. It stikes me as strange that a function like .ReadByte() doesn’t return a byte in the first place. Is there a reason why MS did it this way?

// Read the remaining bytes, byte by byte.
while(count < memStream.Length)
{
    byteArray[count++] =
        Convert.ToByte(memStream.ReadByte());
}

a thought occured to me. Perhaps this comes down to usage. Perhaps ReadByte() is often used to retrieve short lengths, which subsequents get consumed in the retrieve via length variety

int length=ms.ReadByte();
ms.Read(buf,0,lenth);

i.e. you can use the length without a cast. Is this a good enough reason?

  • 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-24T02:15:15+00:00Added an answer on May 24, 2026 at 2:15 am

    This is not specific to Memory stream, rather it is because of the design of base class “Stream” and the reason for that is

    Return value:

    The unsigned byte cast to an Int32, or -1 if at the end of the stream.

    -1 cannot be represented using unsigned byte

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

Sidebar

Related Questions

With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
I got this example from one StackOverflow question that was asked but I couldn't
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval
In this example from the App Engine docs , why does the example declare
I tried to copy this example from this Multiprocessing lecture by jesse noller (as
Why in this example from MSDN, in GetEnumerator method, PeopleEnum returns IEnumerator ? public
thank you for looking i got this example from my book but i cant
I am trying to follow this example (from p137 of Rob Pickering's Foundations of
Can someone explain how New works with the With keyword in this example from
This example is from php.net: <?php function Test() { static $a = 0; echo

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.