Re: using FileStream
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Sun, 10 Aug 2008 13:51:03 +0100
Tony Johansson <johansson.andersson@xxxxxxxxx> wrote:
Here I have an small piece of code from a program.
I have read about the last parameter of GetBytes but I can't really
understand it's use.
I mean that the GC would take care of flushing the Encoder object e without
having to say that.
What does this have to do with a FileStream (your subject line)?
So somebody explain the reason for having this last parameter in the method
GetBytes ?
Encoder e = Encoding.UTF8.GetEncoder();
e.GetBytes(chardata, 0, chardata.length, byteDataArray, 0, true):
It's so that you can either reuse the encoder with a completely
different set of bytes, *or* you can reuse it with subsequent bytes.
This is important if the last set of bytes you passed ended half way
through a character. If you flush the encoder, it will start again from
scratch. If you don't, it will expect the second half of the character
to be at the start of the next block of data.
Most of the time you don't need Encoder though - simply using Encoding
is good enough in most cases.
--
Jon Skeet - <skeet@xxxxxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
.
- Follow-Ups:
- Re: using FileStream
- From: Tony Johansson
- Re: using FileStream
- References:
- using FileStream
- From: Tony Johansson
- using FileStream
- Prev by Date: Re: How do you make an array persistent?
- Next by Date: Re: ushort[] myBigKey = new ushort[100]; //how do I use myBigKey as one long key??
- Previous by thread: using FileStream
- Next by thread: Re: using FileStream
- Index(es):
Relevant Pages
|