This documentation is archived and is not being maintained.

UTF8Encoding.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 ()
Not applicable.

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.


For security reasons, your applications are recommended to enable error detection by using the constructor that accepts a throwOnInvalidBytes parameter and setting that parameter to true.

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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0