By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

MemoryStream.WriteByte()

P: n/a
Dim ms As MemoryStream = New MemoryStream(100)

ms.WriteByte("=")

triggers invalid cast error ...

but

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

does not ...

but isn't Asc() producing a 2-byte representation of a Char
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 24 Aug 2004 21:49:59 -0700, John A Grandy wrote:
Dim ms As MemoryStream = New MemoryStream(100)

ms.WriteByte("=")

triggers invalid cast error ...

but

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

does not ...

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


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]
Nov 21 '05 #2

P: n/a
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.Write(Char) or
StreamWriter.Write(Char).

Hope this helps
Jay

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
Dim ms As MemoryStream = New MemoryStream(100)

ms.WriteByte("=")

triggers invalid cast error ...

but

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

does not ...

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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.