Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
UTF8Encoding Class
 UTF8Encoding Constructor

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
UTF8Encoding Constructor

Initializes a new instance of the UTF8Encoding class.

Namespace:  System.Text
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Sub New
Visual Basic (Usage)
Dim instance As New UTF8Encoding()
C#
public UTF8Encoding()
Visual C++
public:
UTF8Encoding()
JScript
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.

NoteNote:

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.

Visual Basic
Imports System
Imports System.Text

Class UTF8EncodingExample

    Public Shared Sub Main()
        Dim utf8 As New UTF8Encoding()
        Dim encodingName As String = utf8.EncodingName
        Console.WriteLine("Encoding name: " & encodingName)
    End Sub 'Main
End Class 'UTF8EncodingExample

C#
using System;
using System.Text;

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

Visual C++
using namespace System;
using namespace System::Text;
int main()
{
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   String^ encodingName = utf8->EncodingName;
   Console::WriteLine( "Encoding name: {0}", encodingName );
}


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker