UnicodeEncoding Constructor

Initializes a new instance of the UnicodeEncoding class.

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

public UnicodeEncoding()

This constructor creates an instance that uses the little-endian byte order, provides 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 creates a new UnicodeEncoding instance and displays the name of the encoding.

using System;
using System.Text;

class Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      UnicodeEncoding unicode = new UnicodeEncoding();
      String encodingName = unicode.WebName;
      outputBlock.Text += "Encoding name: " + encodingName + "\n";
// The example displays the following output:
//       Encoding name: utf-16


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions