Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

UTF8Encoding Constructor ()

Initializes a new instance of the UTF8Encoding class.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

public UTF8Encoding ()
public UTF8Encoding ()
public function UTF8Encoding ()

This constructor creates an instance that does not provide a Unicode byte order mark and does not throw an exception when an invalid encoding is detected.

Caution noteCaution

For security reasons, it is recommended that you enable error detection by using the constructor that accepts a throwOnInvalidBytes parameter and set that parameter to true.

Optionally, the UTF8Encoding provides a preamble, which is an array of bytes that you can prefix to the sequence of bytes resulting from the encoding process. If the preamble contains a byte order mark (code point U+FEFF), it helps the decoder determine the byte order and the transformation format or UTF. The Unicode byte order mark is serialized as EF BB BF (in hexadecimal). The GetPreamble method returns an array of bytes containing the byte order mark.

For more information on Unicode encoding, byte order, and the byte order mark, see The Unicode Standard at www.unicode.org.

The following example demonstrates how to create a new UTF8Encoding instance and display the name of the encoding.

using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        UTF8Encoding utf8 = new UTF8Encoding();
        String encodingName = utf8.EncodingName;
        Console.WriteLine("Encoding name: " + encodingName);
    }
}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[] args)
    {
        UTF8Encoding utf8 = new UTF8Encoding();
        String encodingName = utf8.get_EncodingName();
        Console.WriteLine(("Encoding name: " + encodingName));
    } //main
} //UTF8EncodingExample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.