MemoryStream.WriteByte()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John A Grandy

    MemoryStream.WriteByte()

    Dim ms As MemoryStream = New MemoryStream(10 0)

    ms.WriteByte("= ")

    triggers invalid cast error ...

    but

    ms.WriteByte(As c("="c))

    does not ...

    but isn't Asc() producing a 2-byte representation of a Char


  • Tom Shelton

    #2
    Re: MemoryStream.Wr iteByte()

    On Tue, 24 Aug 2004 21:49:59 -0700, John A Grandy wrote:
    [color=blue]
    > Dim ms As MemoryStream = New MemoryStream(10 0)
    >
    > ms.WriteByte("= ")
    >
    > triggers invalid cast error ...
    >
    > but
    >
    > ms.WriteByte(As c("="c))
    >
    > does not ...
    >
    > but isn't Asc() producing a 2-byte representation of a Char[/color]

    but the value is less then 256, so can be cast into a byte... This might
    complain though with Option Strict On, since it would be a narrowing
    conversion (you do have option strict on, right? :)

    --
    Tom Shelton [MVP]

    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: MemoryStream.Wr iteByte()

      John,
      In addition to Tom's comment.

      Asc returns the ANSI value of the character, ANSI is defined as a 8-bit
      value.

      AscW returns the Unicode value of the character, Unicode is defined as an
      16-bit code point (in .NET).

      I would create a BinaryWriter or a StreamWriter over the MemoryStream with
      the proper encoding set, and call BinaryWriter.Wr ite(Char) or
      StreamWriter.Wr ite(Char).

      Hope this helps
      Jay

      "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
      news:eHXY97liEH A.1644@tk2msftn gp13.phx.gbl...[color=blue]
      > Dim ms As MemoryStream = New MemoryStream(10 0)
      >
      > ms.WriteByte("= ")
      >
      > triggers invalid cast error ...
      >
      > but
      >
      > ms.WriteByte(As c("="c))
      >
      > does not ...
      >
      > but isn't Asc() producing a 2-byte representation of a Char
      >
      >[/color]


      Comment

      Working...