Bagikan melalui


UTF7Encoding Konstruktor

Definisi

Menginisialisasi instans baru kelas UTF7Encoding.

Overload

UTF7Encoding()
Kedaluwarsa.

Menginisialisasi instans baru kelas UTF7Encoding.

UTF7Encoding(Boolean)
Kedaluwarsa.

Menginisialisasi instans baru kelas UTF7Encoding. Parameter menentukan apakah akan mengizinkan karakter opsional.

UTF7Encoding()

Sumber:
UTF7Encoding.cs
Sumber:
UTF7Encoding.cs
Sumber:
UTF7Encoding.cs

Perhatian

The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.

Menginisialisasi instans baru kelas UTF7Encoding.

public:
 UTF7Encoding();
public UTF7Encoding ();
[System.Obsolete("The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.", DiagnosticId="SYSLIB0001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public UTF7Encoding ();
Public Sub New ()
Atribut

Contoh

Contoh kode berikut menunjukkan cara membuat instans baru UTF7Encoding dan menampilkan nama pengodean.

using namespace System;
using namespace System::Text;
int main()
{
   UTF7Encoding^ utf7 = gcnew UTF7Encoding;
   String^ encodingName = utf7->EncodingName;
   Console::WriteLine( "Encoding name: {0}", encodingName );
}
using System;
using System.Text;

class UTF7EncodingExample {
    public static void Main() {
        UTF7Encoding utf7 = new UTF7Encoding();
        String encodingName = utf7.EncodingName;
        Console.WriteLine("Encoding name: " + encodingName);
    }
}
Imports System.Text

Class UTF7EncodingExample
    
    Public Shared Sub Main()
        Dim utf7 As New UTF7Encoding()
        Dim encodingName As String = utf7.EncodingName
        Console.WriteLine("Encoding name: " & encodingName)
    End Sub
End Class

Keterangan

Konstruktor ini membuat instans yang tidak mengizinkan karakter opsional. Memanggil UTF7Encoding konstruktor setara dengan memanggil konstruktor yang mengambil allowOptionals parameter dan menentukan false parameter tersebutUTF7Encoding.UTF7Encoding(Boolean).

Jika instans memungkinkan karakter opsional, titik kode Unicode dikodekan dengan karakter opsional yang sesuai alih-alih karakter dasar 64 yang dimodifikasi. Karakter opsional adalah tanda seru ("!"), garis miring mundur ("\"), garis vertikal ("|"), tanda kutip ganda ("""), tanda angka ("#"), tanda dolar ("$"), tanda persen ("%"), ampersand ("&"), tanda bintang ("*"), titik koma (";"), tanda sudut kiri ("<"), kurung sudut kanan (">"), kurung kurawal kiri ("{"), kurung kurawal kanan ("}"), kurung siku kiri ("["), kurung siku kanan ("]"), tanda sama dengan ("="), tanda ("@"), aksen sirkumfleks ("^"), garis bawah ("_"), dan aksen kubur ("'").

Catatan

UTF7Encoding tidak menyediakan deteksi kesalahan. Untuk alasan keamanan, aplikasi Anda disarankan untuk menggunakan UTF8Encoding, , UnicodeEncodingatau UTF32Encoding dan mengaktifkan deteksi kesalahan.

Berlaku untuk

UTF7Encoding(Boolean)

Sumber:
UTF7Encoding.cs
Sumber:
UTF7Encoding.cs
Sumber:
UTF7Encoding.cs

Perhatian

The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.

Menginisialisasi instans baru kelas UTF7Encoding. Parameter menentukan apakah akan mengizinkan karakter opsional.

public:
 UTF7Encoding(bool allowOptionals);
public UTF7Encoding (bool allowOptionals);
[System.Obsolete("The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.", DiagnosticId="SYSLIB0001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public UTF7Encoding (bool allowOptionals);
new System.Text.UTF7Encoding : bool -> System.Text.UTF7Encoding
[<System.Obsolete("The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.", DiagnosticId="SYSLIB0001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Text.UTF7Encoding : bool -> System.Text.UTF7Encoding
Public Sub New (allowOptionals As Boolean)

Parameter

allowOptionals
Boolean

true untuk menentukan bahwa karakter opsional diperbolehkan; jika tidak, false.

Atribut

Contoh

Contoh kode berikut menunjukkan cara membuat instans baru UTF7Encoding yang memungkinkan karakter opsional.

using namespace System;
using namespace System::Text;
using namespace System::Collections;
void ShowArray( Array^ theArray )
{
   IEnumerator^ myEnum = theArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ o = safe_cast<Object^>(myEnum->Current);
      Console::Write( "[{0}]", o );
   }

   Console::WriteLine();
}

int main()
{
   
   // A few optional characters.
   String^ chars = "!@#$";
   
   // The default Encoding does not allow optional characters.
   // Alternate Byte values are used.
   UTF7Encoding^ utf7 = gcnew UTF7Encoding;
   array<Byte>^bytes1 = utf7->GetBytes( chars );
   Console::WriteLine( "Default UTF7 Encoding:" );
   ShowArray( bytes1 );
   
   // Convert back to characters.
   Console::WriteLine( "Characters:" );
   ShowArray( utf7->GetChars( bytes1 ) );
   
   // Now, allow optional characters.
   // Optional characters are encoded with their normal code points.
   UTF7Encoding^ utf7AllowOptionals = gcnew UTF7Encoding( true );
   array<Byte>^bytes2 = utf7AllowOptionals->GetBytes( chars );
   Console::WriteLine( "UTF7 Encoding with optional characters allowed:" );
   ShowArray( bytes2 );
   
   // Convert back to characters.
   Console::WriteLine( "Characters:" );
   ShowArray( utf7AllowOptionals->GetChars( bytes2 ) );
}
using System;
using System.Text;

class UTF7EncodingExample {
    public static void Main() {

        // A few optional characters.
        string chars = "!@#$";

        // The default Encoding does not allow optional characters.
        // Alternate byte values are used.
        UTF7Encoding utf7 = new UTF7Encoding();
        Byte[] bytes1 = utf7.GetBytes(chars);
        
        Console.WriteLine("Default UTF7 Encoding:");
        ShowArray(bytes1);

        // Convert back to characters.
        Console.WriteLine("Characters:");
        ShowArray(utf7.GetChars(bytes1));

        // Now, allow optional characters.
        // Optional characters are encoded with their normal code points.
        UTF7Encoding utf7AllowOptionals = new UTF7Encoding(true);
        Byte[] bytes2 = utf7AllowOptionals.GetBytes(chars);
        
        Console.WriteLine("UTF7 Encoding with optional characters allowed:");
        ShowArray(bytes2);

        // Convert back to characters.
        Console.WriteLine("Characters:");
        ShowArray(utf7AllowOptionals.GetChars(bytes2));
    }

    public static void ShowArray(Array theArray) {
        foreach (Object o in theArray) {
            Console.Write("[{0}]", o);
        }
        Console.WriteLine();
    }
}
Imports System.Text

Class UTF7EncodingExample
    
    Public Shared Sub Main()
        
        ' A few optional characters.
        Dim chars As String = "!@#$"
        
        ' The default Encoding does not allow optional characters.
        ' Alternate byte values are used.
        Dim utf7 As New UTF7Encoding()
        Dim bytes1 As Byte() = utf7.GetBytes(chars)
        
        Console.WriteLine("Default UTF7 Encoding:")
        ShowArray(bytes1)
        
        ' Convert back to characters.
        Console.WriteLine("Characters:")
        ShowArray(utf7.GetChars(bytes1))
        
        ' Now, allow optional characters.
        ' Optional characters are encoded with their normal code points.
        Dim utf7AllowOptionals As New UTF7Encoding(True)
        Dim bytes2 As Byte() = utf7AllowOptionals.GetBytes(chars)
        
        Console.WriteLine("UTF7 Encoding with optional characters allowed:")
        ShowArray(bytes2)
        
        ' Convert back to characters.
        Console.WriteLine("Characters:")
        ShowArray(utf7AllowOptionals.GetChars(bytes2))
    End Sub
    
    
    Public Shared Sub ShowArray(theArray As Array)
        Dim o As Object
        For Each o In  theArray
            Console.Write("[{0}]", o)
        Next o
        Console.WriteLine()
    End Sub
End Class

Keterangan

Jika instans memungkinkan karakter opsional, titik kode Unicode dikodekan dengan karakter opsional yang sesuai alih-alih karakter dasar 64 yang dimodifikasi. Karakter opsional adalah tanda seru ("!"), garis miring mundur ("\"), garis vertikal ("|"), tanda kutip ganda ("""), tanda angka ("#"), tanda dolar ("$"), tanda persen ("%"), ampersand ("&"), tanda bintang ("*"), titik koma (";"), tanda sudut kiri ("<"), kurung sudut kanan (">"), kurung kurawal kiri ("{"), kurung kurawal kanan ("}"), kurung siku kiri ("["), kurung siku kanan ("]"), tanda sama dengan ("="), tanda ("@"), aksen sirkumfleks ("^"), garis bawah ("_"), dan aksen kubur ("'").

Catatan

UTF7Encoding tidak menyediakan deteksi kesalahan. Untuk alasan keamanan, aplikasi Anda disarankan untuk menggunakan UTF8Encoding, , UnicodeEncodingatau UTF32Encoding dan mengaktifkan deteksi kesalahan.

Berlaku untuk