Rolls, Robert [mailto:[EMAIL PROTECTED]] wrote:

> I'm a little bit confused over all the encoding types and the
> documentation and I have a query with the following -
>
> is this equivalent -
>
> Byte[] a = Encoding.ASCII.GetBytes("Fred");
> Byte[] b = ASCIIEncoding.ASCII.GetBytes("Fred");
>
> and the same for UnicodeEncoding, UTF7Encoding, UTF8Encoding?
>
> The documentation also seems all over the place especially
> what public members the class is supposed to expose?

Yes they are equivalent. ASCIIEncoding subclasses Encoding and Encoding has
a static member (singleton) which is an instance of type ASCIIEncoding. So
when you do ASCIIEncoding.ASCII, your really just getting Encoding.ASCII.
It's a bit tricky when you first look at it, but if you understand the class
design and chain of inheritance it makes sense.

Personally, I think using "Encoding.ASCII" in code makes more sense in terms
of readability.

HTH,
Drew

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to