[Mono-list] Socket code.

Jonathan Pryor jonpryor@vt.edu
Sun, 22 Feb 2004 13:51:18 -0500


Below...

On Sun, 2004-02-22 at 13:06, George Farris wrote:
<snip/>
> > Shouldn't it be:
> > 
> >  	s = Encoding.ASCII.GetString(bytes, 0, len);
> >  	buf.Append(s);
> > 
> 
> Well the docs on GetString say it can be just a byte[].  

Yes, GetString(byte[]) exists, but it's equivalent to this:

	string GetString (byte[] bytes)
	{
		return GetString (bytes, 0, bytes.Length);
	}

So this is only valid if `bytes' is full.  Otherwise (when you've read
fewer than `bytes.Length' bytes) the end of your string will contain
garbage data.  The `GetString (bytes, 0, len)' fixes this, so GetString
will only convert valid data.

 - Jon