UnicodeEncoding 类

定义

表示 Unicode 字符的 UTF-16 编码。Represents a UTF-16 encoding of Unicode characters.

public ref class UnicodeEncoding : System::Text::Encoding
public class UnicodeEncoding : System.Text.Encoding
[System.Serializable]
public class UnicodeEncoding : System.Text.Encoding
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class UnicodeEncoding : System.Text.Encoding
type UnicodeEncoding = class
    inherit Encoding
Public Class UnicodeEncoding
Inherits Encoding
继承
UnicodeEncoding
属性

示例

下面的示例演示如何使用 UnicodeEncoding 对象将 Unicode 字符的字符串编码为字节数组。The following example demonstrates how to encode a string of Unicode characters into a byte array by using a UnicodeEncoding object. 字节数组解码为字符串,以表明不会丢失数据。The byte array is decoded into a string to demonstrate that there is no loss of data.

using namespace System;
using namespace System::Text;
using namespace System::Collections;
int main()
{
   
   // The encoding.
   UnicodeEncoding^ unicode = gcnew UnicodeEncoding;
   
   // Create a String* that contains Unicode characters.
   String^ unicodeString = L"This Unicode string contains two characters with codes outside the traditional ASCII code range, Pi (\u03a0) and Sigma (\u03a3).";
   Console::WriteLine( "Original string:" );
   Console::WriteLine( unicodeString );
   
   // Encode the String*.
   array<Byte>^encodedBytes = unicode->GetBytes( unicodeString );
   Console::WriteLine();
   Console::WriteLine( "Encoded bytes:" );
   IEnumerator^ myEnum = encodedBytes->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Byte b = safe_cast<Byte>(myEnum->Current);
      Console::Write( "[{0}]", b );
   }

   Console::WriteLine();
   
   // Decode bytes back to String*.
   // Notice Pi and Sigma characters are still present.
   String^ decodedString = unicode->GetString( encodedBytes );
   Console::WriteLine();
   Console::WriteLine( "Decoded bytes:" );
   Console::WriteLine( decodedString );
}

using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        // The encoding.
        UnicodeEncoding unicode = new UnicodeEncoding();
        
        // Create a string that contains Unicode characters.
        String unicodeString =
            "This Unicode string contains two characters " +
            "with codes outside the traditional ASCII code range, " +
            "Pi (\u03a0) and Sigma (\u03a3).";
        Console.WriteLine("Original string:");
        Console.WriteLine(unicodeString);

        // Encode the string.
        Byte[] encodedBytes = unicode.GetBytes(unicodeString);
        Console.WriteLine();
        Console.WriteLine("Encoded bytes:");
        foreach (Byte b in encodedBytes) {
            Console.Write("[{0}]", b);
        }
        Console.WriteLine();
        
        // Decode bytes back to string.
        // Notice Pi and Sigma characters are still present.
        String decodedString = unicode.GetString(encodedBytes);
        Console.WriteLine();
        Console.WriteLine("Decoded bytes:");
        Console.WriteLine(decodedString);
    }
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings

Class UnicodeEncodingExample
    
    Public Shared Sub Main()
        ' The encoding.
        Dim uni As New UnicodeEncoding()
        
        ' Create a string that contains Unicode characters.
        Dim unicodeString As String = _
            "This Unicode string contains two characters " & _
            "with codes outside the traditional ASCII code range, " & _
            "Pi (" & ChrW(928) & ") and Sigma (" & ChrW(931) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine(unicodeString)
        
        ' Encode the string.
        Dim encodedBytes As Byte() = uni.GetBytes(unicodeString)
        Console.WriteLine()
        Console.WriteLine("Encoded bytes:")
        Dim b As Byte
        For Each b In  encodedBytes
            Console.Write("[{0}]", b)
        Next b
        Console.WriteLine()
        
        ' Decode bytes back to string.
        ' Notice Pi and Sigma characters are still present.
        Dim decodedString As String = uni.GetString(encodedBytes)
        Console.WriteLine()
        Console.WriteLine("Decoded bytes:")
        Console.WriteLine(decodedString)
    End Sub
End Class

下面的示例使用与前一个相同的字符串,只不过它将已编码的字节写入文件,并使用字节顺序标记(BOM)作为字节流的前缀。The following example uses the same string as the previous one, except that it writes the encoded bytes to a file and prefixes the byte stream with a byte order mark (BOM). 它然后两个不同的方式读取文件: 为通过使用文本文件StreamReader对象; 和二进制文件。 如您所料,在两种情况下是 BOM 包括在新读取字符串。It then reads the file in two different ways: as a text file by using a StreamReader object; and as a binary file. 正如您所料,新读取的字符串都不包含 BOM。As you would expect, neither newly-read string includes the BOM.

using System;
using System.IO;
using System.Text;

public class Example
{
   public static void Main()
   {
        // Create a UTF-16 encoding that supports a BOM.
        Encoding unicode = new UnicodeEncoding();

        // A Unicode string with two characters outside an 8-bit code range.
        String unicodeString =
            "This Unicode string has 2 characters outside the " +
            "ASCII range: \n" +
            "Pi (\u03A0)), and Sigma (\u03A3).";
        Console.WriteLine("Original string:");
        Console.WriteLine(unicodeString);
        Console.WriteLine();

        // Encode the string.
        Byte[] encodedBytes = unicode.GetBytes(unicodeString);
        Console.WriteLine("The encoded string has {0} bytes.\n",
                          encodedBytes.Length);

        // Write the bytes to a file with a BOM.
        var fs = new FileStream(@".\UTF8Encoding.txt", FileMode.Create);
        Byte[] bom = unicode.GetPreamble();
        fs.Write(bom, 0, bom.Length);
        fs.Write(encodedBytes, 0, encodedBytes.Length);
        Console.WriteLine("Wrote {0} bytes to the file.\n", fs.Length);
        fs.Close();

        // Open the file using StreamReader.
        var sr = new StreamReader(@".\UTF8Encoding.txt");
        String newString = sr.ReadToEnd();
        sr.Close();
        Console.WriteLine("String read using StreamReader:");
        Console.WriteLine(newString);
        Console.WriteLine();

        // Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(@".\UTF8Encoding.txt", FileMode.Open);
        Byte[] bytes = new Byte[fs.Length];
        fs.Read(bytes, 0, (int)fs.Length);
        fs.Close();

        String decodedString = unicode.GetString(bytes);
        Console.WriteLine("Decoded bytes:");
        Console.WriteLine(decodedString);
   }
}
// The example displays the following output:
//    Original string:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    The encoded string has 172 bytes.
//
//    Wrote 174 bytes to the file.
//
//    String read using StreamReader:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
//
//    Decoded bytes:
//    This Unicode string has 2 characters outside the ASCII range:
//    Pi (π), and Sigma (Σ).
Imports System.IO
Imports System.Text

Class Example
    Public Shared Sub Main()
        ' Create a UTF-16 encoding that supports a BOM.
        Dim unicode As New UnicodeEncoding()
        
        ' A Unicode string with two characters outside an 8-bit code range.
        Dim unicodeString As String = _
            "This Unicode string has 2 characters outside the " &
            "ASCII range: " & vbCrLf &
            "Pi (" & ChrW(&h03A0) & "), and Sigma (" & ChrW(&h03A3) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine(unicodeString)
        Console.WriteLine()
        
        ' Encode the string.
        Dim encodedBytes As Byte() = unicode.GetBytes(unicodeString)
        Console.WriteLine("The encoded string has {0} bytes.",
                          encodedBytes.Length)
        Console.WriteLine()
        
        ' Write the bytes to a file with a BOM.
        Dim fs As New FileStream(".\UnicodeEncoding.txt", FileMode.Create)
        Dim bom() As Byte = unicode.GetPreamble()
        fs.Write(bom, 0, bom.Length)
        fs.Write(encodedBytes, 0, encodedBytes.Length)
        Console.WriteLine("Wrote {0} bytes to the file.", fs.Length)
        fs.Close()
        Console.WriteLine()
        
        ' Open the file using StreamReader.
        Dim sr As New StreamReader(".\UnicodeEncoding.txt")
        Dim newString As String = sr.ReadToEnd()
        sr.Close()
        Console.WriteLine("String read using StreamReader:")
        Console.WriteLine(newString)
        Console.WriteLine()
        
        ' Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(".\UnicodeEncoding.txt", FileMode.Open)
        Dim bytes(fs.Length - 1) As Byte
        fs.Read(bytes, 0, fs.Length)
        fs.Close()

        Dim decodedString As String = unicode.GetString(bytes)
        Console.WriteLine("Decoded bytes:")
        Console.WriteLine(decodedString)
    End Sub
End Class
' The example displays the following output:
'    Original string:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    The encoded string has 172 bytes.
'
'    Wrote 174 bytes to the file.
'
'    String read using StreamReader:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).
'
'    Decoded bytes:
'    This Unicode string has 2 characters outside the ASCII range:
'    Pi (π), and Sigma (Σ).

注解

编码是将一组 Unicode 字符转换为一个字节序列的过程。Encoding is the process of transforming a set of Unicode characters into a sequence of bytes. 解码是将编码字节序列转换为一组 Unicode 字符的过程。Decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters.

Unicode 标准为每个受支持脚本中的每个字符分配一个码位(数字)。The Unicode Standard assigns a code point (a number) to each character in every supported script. Unicode 转换格式(UTF)是对该码位进行编码的一种方法。A Unicode Transformation Format (UTF) is a way to encode that code point. Unicode 标准使用以下 UTFs:The Unicode Standard uses the following UTFs:

  • UTF-8,它将每个码位表示为一至四个字节的序列。UTF-8, which represents each code point as a sequence of one to four bytes.

  • UTF-16,它将每个码位表示为一个到 2 16 位整数的序列。UTF-16, which represents each code point as a sequence of one to two 16-bit integers.

  • 32,它将每个码位表示为32位整数。UTF-32, which represents each code point as a 32-bit integer.

有关 System.Text支持的 UTFs 和其他编码的详细信息,请参阅.NET Framework 中的字符编码For more information about the UTFs and other encodings supported by System.Text, see Character Encoding in the .NET Framework.

UnicodeEncoding 类表示 UTF-16 编码。The UnicodeEncoding class represents a UTF-16 encoding. 编码器可以使用大 endian 字节顺序(首先是最重要的字节),也可以是 little endian 字节顺序(首先是最小有效字节)。The encoder can use either big endian byte order (most significant byte first) or little endian byte order (least significant byte first). 例如,拉丁文大写字母 A (码位 U + 0041)按以下方式序列化(十六进制):For example, the Latin Capital Letter A (code point U+0041) is serialized as follows (in hexadecimal):

  • 大 endian 字节顺序: 00 00 00 41Big endian byte order: 00 00 00 41

  • 小 endian 字节顺序: 41 00 00 00Little endian byte order: 41 00 00 00

通常,使用特定平台的本机字节顺序存储 Unicode 字符会更有效。It is generally more efficient to store Unicode characters using the native byte order of a particular platform. 例如,最好使用 little endian 平台(如 Intel 计算机)上的 little endian 字节顺序。For example, it is better to use the little endian byte order on little endian platforms, such as Intel computers. UnicodeEncoding 类对应于 Windows 代码页1200(little endian 字节顺序)和1201(大 endian 字节顺序)。The UnicodeEncoding class corresponds to the Windows code pages 1200 (little endian byte order) and 1201 (big endian byte order). 可以通过调用 BitConverter.IsLittleEndian 方法来确定特定体系结构的 "endian"。You can determine the "endianness" of a particular architecture by calling the BitConverter.IsLittleEndian method.

(可选) UnicodeEncoding 对象提供字节顺序标记(BOM),这是一个字节数组,可以作为编码过程中所产生的字节序列的前缀。Optionally, the UnicodeEncoding object provides a byte order mark (BOM), which is an array of bytes that can be prefixed to the sequence of bytes resulting from the encoding process. 如果引言包含字节顺序标记(BOM),则它有助于解码器确定字节顺序和转换格式或 UTF。If the preamble contains a byte order mark (BOM), it helps the decoder determine the byte order and the transformation format or UTF.

如果UnicodeEncoding实例配置为提供 BOM,可以通过调用检索GetPreamble方法; 否则,该方法返回空数组。If the UnicodeEncoding instance is configured to provide a BOM, you can retrieve it by calling the GetPreamble method; otherwise, the method returns an empty array. 请注意,即使UnicodeEncodingBOM 支持的配置对象时,必须包含 BOM 将编码的字节流作为相应; 开头的编码方法UnicodeEncoding类执行未自动执行此操作。Note that, even if a UnicodeEncoding object is configured for BOM support, you must include the BOM at the beginning of the encoded byte stream as appropriate; the encoding methods of the UnicodeEncoding class do not do this automatically.

注意

若要启用错误检测并使类实例更安全,应通过调用 UnicodeEncoding(Boolean, Boolean, Boolean) 构造函数并将其 throwOnInvalidBytes 参数设置为 true来实例化 UnicodeEncoding 的对象。To enable error detection and to make the class instance more secure, you should instantiate a UnicodeEncoding object by calling the UnicodeEncoding(Boolean, Boolean, Boolean) constructor and setting its throwOnInvalidBytes argument to true. 使用错误检测时,检测到无效字符或字节序列的方法会引发 ArgumentExceptionWith error detection, a method that detects an invalid sequence of characters or bytes throws a ArgumentException. 如果未检测到错误,则不会引发异常,并且通常会忽略无效序列。Without error detection, no exception is thrown, and the invalid sequence is generally ignored.

您可以通过多种方式实例化 UnicodeEncoding 对象,具体取决于您是否希望它提供字节顺序标记(BOM)、是否需要使用大字节序或小字节序编码,以及是否要启用错误检测。You can instantiate a UnicodeEncoding object in a number of ways, depending on whether you want to it to provide a byte order mark (BOM), whether you want big-endian or little-endian encoding, and whether you want to enable error detection. 下表列出了 UnicodeEncoding 构造函数和返回 UnicodeEncoding 对象的 Encoding 属性。The following table lists the UnicodeEncoding constructors and the Encoding properties that return a UnicodeEncoding object.

成员Member 字节排序方式Endianness BOMBOM 错误检测Error detection
BigEndianUnicode 大字节序Big-endian Yes 否(替换回退)No (Replacement fallback)
Encoding.Unicode 小字节序Little-endian Yes 否(替换回退)No (Replacement fallback)
UnicodeEncoding.UnicodeEncoding() 小字节序Little-endian Yes 否(替换回退)No (Replacement fallback)
UnicodeEncoding(Boolean, Boolean) 可配置性Configurable 可配置性Configurable 否(替换回退)No (Replacement fallback)
UnicodeEncoding.UnicodeEncoding(Boolean, Boolean, Boolean) 可配置性Configurable 可配置性Configurable 可配置性Configurable

GetByteCount 方法确定导致对一组 Unicode 字符进行编码的字节数,并且 GetBytes 方法执行实际编码。The GetByteCount method determines how many bytes result in encoding a set of Unicode characters, and the GetBytes method performs the actual encoding.

同样,GetCharCount 方法决定了多少个字符会导致对一个字节序列进行解码,而 GetCharsGetString 方法执行实际解码。Likewise, the GetCharCount method determines how many characters result in decoding a sequence of bytes, and the GetChars and GetString methods perform the actual decoding.

对于可以在编码或解码跨多个块的数据时保存状态信息的编码器或解码器(例如,100000个字符段中编码的1000000个字符),请分别使用 GetEncoderGetDecoder 属性。For an encoder or decoder that is able to save state information when encoding or decoding data that spans multiple blocks (such as string of 1 million characters that is encoded in 100,000-character segments), use the GetEncoder and GetDecoder properties, respectively.

构造函数

UnicodeEncoding()

初始化 UnicodeEncoding 类的新实例。Initializes a new instance of the UnicodeEncoding class.

UnicodeEncoding(Boolean, Boolean)

初始化 UnicodeEncoding 类的新实例。Initializes a new instance of the UnicodeEncoding class. 参数指定是否使用 Big-Endian 字节顺序以及 GetPreamble() 方法是否返回 Unicode 字节顺序标记。Parameters specify whether to use the big endian byte order and whether the GetPreamble() method returns a Unicode byte order mark.

UnicodeEncoding(Boolean, Boolean, Boolean)

初始化 UnicodeEncoding 类的新实例。Initializes a new instance of the UnicodeEncoding class. 参数指定是否使用 Big-Endian 字节顺序、是否提供 Unicode 字节顺序标记以及当检测到无效编码时是否引发异常。Parameters specify whether to use the big endian byte order, whether to provide a Unicode byte order mark, and whether to throw an exception when an invalid encoding is detected.

字段

CharSize

表示 Unicode 字符大小(以字节为单位)。Represents the Unicode character size in bytes. 此字段为常数。This field is a constant.

属性

BodyName

在派生类中重写时,获取可与邮件代理正文标记一起使用的当前编码的名称。When overridden in a derived class, gets a name for the current encoding that can be used with mail agent body tags.

(继承自 Encoding)
CodePage

在派生类中重写时,获取当前 Encoding 的代码页标识符。When overridden in a derived class, gets the code page identifier of the current Encoding.

(继承自 Encoding)
DecoderFallback

获取或设置当前 DecoderFallback 对象的 Encoding 对象。Gets or sets the DecoderFallback object for the current Encoding object.

(继承自 Encoding)
EncoderFallback

获取或设置当前 EncoderFallback 对象的 Encoding 对象。Gets or sets the EncoderFallback object for the current Encoding object.

(继承自 Encoding)
EncodingName

在派生类中重写时,获取当前编码的用户可读说明。When overridden in a derived class, gets the human-readable description of the current encoding.

(继承自 Encoding)
HeaderName

在派生类中重写时,获取可与邮件代理头标记一起使用的当前编码的名称。When overridden in a derived class, gets a name for the current encoding that can be used with mail agent header tags.

(继承自 Encoding)
IsBrowserDisplay

在派生类中重写时,获取一个值,该值指示浏览器客户端是否可以使用当前的编码显示内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for displaying content.

(继承自 Encoding)
IsBrowserSave

在派生类中重写时,获取一个值,该值指示浏览器客户端是否可以使用当前的编码保存内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for saving content.

(继承自 Encoding)
IsMailNewsDisplay

在派生类中重写时,获取一个值,该值指示邮件和新闻客户端是否可以使用当前的编码显示内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.

(继承自 Encoding)
IsMailNewsSave

在派生类中重写时,获取一个值,该值指示邮件和新闻客户端是否可以使用当前的编码保存内容。When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for saving content.

(继承自 Encoding)
IsReadOnly

在派生类中重写时,获取一个值,该值指示当前的编码是否为只读。When overridden in a derived class, gets a value indicating whether the current encoding is read-only.

(继承自 Encoding)
IsSingleByte

在派生类中重写时,获取一个值,该值指示当前的编码是否使用单字节码位。When overridden in a derived class, gets a value indicating whether the current encoding uses single-byte code points.

(继承自 Encoding)
Preamble

获取采用 UTF-16 格式编码的 Unicode 字节顺序标记(如果此对象配置为提供一个这样的标记)。Gets a Unicode byte order mark encoded in UTF-16 format, if this object is configured to supply one.

WebName

在派生类中重写时,获取在 Internet 编号分配管理机构 (IANA) 注册的当前编码的名称。When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.

(继承自 Encoding)
WindowsCodePage

在派生类中重写时,获取与当前编码最紧密对应的 Windows 操作系统代码页。When overridden in a derived class, gets the Windows operating system code page that most closely corresponds to the current encoding.

(继承自 Encoding)

方法

Clone()

当在派生类中重写时,创建当前 Encoding 对象的一个卷影副本。When overridden in a derived class, creates a shallow copy of the current Encoding object.

(继承自 Encoding)
Equals(Object)

确定指定的 Object 是否等于当前的 UnicodeEncoding 对象。Determines whether the specified Object is equal to the current UnicodeEncoding object.

GetByteCount(Char*, Int32)

计算对从指定的字符指针开始的一组字符进行编码时产生的字节数。Calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer.

GetByteCount(Char[])

在派生类中重写时,计算对指定字符数组中的所有字符进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding all the characters in the specified character array.

(继承自 Encoding)
GetByteCount(Char[], Int32, Int32)

计算对指定字符数组中的一组字符进行编码时产生的字节数。Calculates the number of bytes produced by encoding a set of characters from the specified character array.

GetByteCount(ReadOnlySpan<Char>)

在派生类中重写时,计算对指定字符范围的字符进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified character span.

(继承自 Encoding)
GetByteCount(String)

计算对指定字符串中的字符进行编码时所产生的字节数。Calculates the number of bytes produced by encoding the characters in the specified string.

GetByteCount(String, Int32, Int32)

在派生类中重写时,计算对指定字符串中的一组字符进行编码所产生的字节数。When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified string.

(继承自 Encoding)
GetBytes(Char*, Int32, Byte*, Int32)

将从指定的字符指针开始的一组字符编码为一个字节序列,并从指定的字节指针开始存储该字节序列。Encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer.

GetBytes(Char[])

在派生类中重写时,将指定字符数组中的所有字符编码为一个字节序列。When overridden in a derived class, encodes all the characters in the specified character array into a sequence of bytes.

(继承自 Encoding)
GetBytes(Char[], Int32, Int32)

在派生类中重写时,将指定字符数组中的一组字符编码为一个字节序列。When overridden in a derived class, encodes a set of characters from the specified character array into a sequence of bytes.

(继承自 Encoding)
GetBytes(Char[], Int32, Int32, Byte[], Int32)

将指定字符数组中的一组字符编码到指定的字节数组中。Encodes a set of characters from the specified character array into the specified byte array.

GetBytes(ReadOnlySpan<Char>, Span<Byte>)

在派生类中重写时,将指定只读范围中的一组字符编码为字节范围。When overridden in a derived class, encodes into a span of bytes a set of characters from the specified read-only span.

(继承自 Encoding)
GetBytes(String)
GetBytes(String, Int32, Int32)

在派生类中重写时,从指定的 count 开始,将指定字符串中由 index 指定的字符数编码为字节数组。When overridden in a derived class, encodes into an array of bytes the number of characters specified by count in the specified string, starting from the specified index.

(继承自 Encoding)
GetBytes(String, Int32, Int32, Byte[], Int32)

将指定 String 中的一组字符编码到指定的字节数组中。Encodes a set of characters from the specified String into the specified byte array.

GetCharCount(Byte*, Int32)

计算对一个字节序列(从指定的字节指针开始)进行解码所产生的字符数。Calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.

GetCharCount(Byte[])

在派生类中重写时,计算对指定字节数组中的所有字节进行解码所产生的字符数。When overridden in a derived class, calculates the number of characters produced by decoding all the bytes in the specified byte array.

(继承自 Encoding)
GetCharCount(Byte[], Int32, Int32)

计算对指定字节数组中的一个字节序列进行解码所产生的字符数。Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

GetCharCount(ReadOnlySpan<Byte>)

在派生类中重写时,计算对提供的只读字节范围进行解码所产生的字符数。When overridden in a derived class, calculates the number of characters produced by decoding the provided read-only byte span.

(继承自 Encoding)
GetChars(Byte*, Int32, Char*, Int32)

将从指定的字节指针开始的一个字节序列解码为一组字符,并从指定的字符指针开始存储这组字符。Decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer.

GetChars(Byte[])

在派生类中重写时,将指定字节数组中的所有字节解码为一组字符。When overridden in a derived class, decodes all the bytes in the specified byte array into a set of characters.

(继承自 Encoding)
GetChars(Byte[], Int32, Int32)

在派生类中重写时,将指定字节数组中的一个字节序列解码为一组字符。When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters.

(继承自 Encoding)
GetChars(Byte[], Int32, Int32, Char[], Int32)

将指定字节数组中的一个字节序列解码为指定的字符数组。Decodes a sequence of bytes from the specified byte array into the specified character array.

GetChars(ReadOnlySpan<Byte>, Span<Char>)

在派生类中重写时,将指定只读字节范围中的所有字节解码为字符范围。When overridden in a derived class, decodes all the bytes in the specified read-only byte span into a character span.

(继承自 Encoding)
GetDecoder()

获取可以将 UTF-16 编码的字节序列转换为 Unicode 字符序列的解码器。Obtains a decoder that converts a UTF-16 encoded sequence of bytes into a sequence of Unicode characters.

GetEncoder()

获取可将 Unicode 字符序列转换为 UTF-16 编码的字节序列的编码器。Obtains an encoder that converts a sequence of Unicode characters into a UTF-16 encoded sequence of bytes.

GetHashCode()

返回当前实例的哈希代码。Returns the hash code for the current instance.

GetMaxByteCount(Int32)

计算对指定数目的字符进行编码时产生的最大字节数。Calculates the maximum number of bytes produced by encoding the specified number of characters.

GetMaxCharCount(Int32)

计算对指定数目的字节进行解码时产生的最大字符数。Calculates the maximum number of characters produced by decoding the specified number of bytes.

GetPreamble()

如果此实例的构造函数请求一个字节顺序标记,则将返回用 UTF-16 格式编码的 Unicode 字节顺序标记。Returns a Unicode byte order mark encoded in UTF-16 format, if the constructor for this instance requests a byte order mark.

GetString(Byte*, Int32)

在派生类中重写时,将在指定地址开始的指定字节数解码为字符串。When overridden in a derived class, decodes a specified number of bytes starting at a specified address into a string.

(继承自 Encoding)
GetString(Byte[])

在派生类中重写时,将指定字节数组中的所有字节解码为一个字符串。When overridden in a derived class, decodes all the bytes in the specified byte array into a string.

(继承自 Encoding)
GetString(Byte[], Int32, Int32)

将字节数组中某个范围的字节解码为一个字符串。Decodes a range of bytes from a byte array into a string.

GetString(ReadOnlySpan<Byte>)

在派生类中重写时,将指定字节范围中的所有字节解码为一个字符串。When overridden in a derived class, decodes all the bytes in the specified byte span into a string.

(继承自 Encoding)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsAlwaysNormalized()

使用默认范式获取一个值,该值指示当前编码是否始终被规范化。Gets a value indicating whether the current encoding is always normalized, using the default normalization form.

(继承自 Encoding)
IsAlwaysNormalized(NormalizationForm)

在派生类中重写时,使用指定范式获取一个值,该值指示当前编码是否始终被规范化。When overridden in a derived class, gets a value indicating whether the current encoding is always normalized, using the specified normalization form.

(继承自 Encoding)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅