Edit

Share via


Encoding Constructors

Definition

Initializes a new instance of the Encoding class.

Overloads

Encoding()

Initializes a new instance of the Encoding class.

Encoding(Int32)

Initializes a new instance of the Encoding class that corresponds to the specified code page.

Encoding(Int32, EncoderFallback, DecoderFallback)

Initializes a new instance of the Encoding class that corresponds to the specified code page with the specified encoder and decoder fallback strategies.

Encoding()

Source:
Encoding.cs
Source:
Encoding.cs
Source:
Encoding.cs

Initializes a new instance of the Encoding class.

C#
protected Encoding();

Remarks

Derived classes override this constructor.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Encoding(Int32)

Source:
Encoding.cs
Source:
Encoding.cs
Source:
Encoding.cs

Initializes a new instance of the Encoding class that corresponds to the specified code page.

C#
protected Encoding(int codePage);

Parameters

codePage
Int32

The code page identifier of the preferred encoding.

-or-

0, to use the default encoding.

Exceptions

codePage is less than zero.

Remarks

Derived classes override this constructor.

Calls to this constructor from a derived class create an Encoding object that uses best-fit fallback for both encoding and decoding operations. Both the DecoderFallback and EncoderFallback properties are read-only and cannot be modified. To control the fallback strategy for a class derived from Encoding, call the Encoding(Int32, EncoderFallback, DecoderFallback) constructor.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Encoding(Int32, EncoderFallback, DecoderFallback)

Source:
Encoding.cs
Source:
Encoding.cs
Source:
Encoding.cs

Initializes a new instance of the Encoding class that corresponds to the specified code page with the specified encoder and decoder fallback strategies.

C#
protected Encoding(int codePage, System.Text.EncoderFallback encoderFallback, System.Text.DecoderFallback decoderFallback);
C#
protected Encoding(int codePage, System.Text.EncoderFallback? encoderFallback, System.Text.DecoderFallback? decoderFallback);

Parameters

codePage
Int32

The encoding code page identifier.

encoderFallback
EncoderFallback

An object that provides an error-handling procedure when a character cannot be encoded with the current encoding.

decoderFallback
DecoderFallback

An object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.

Exceptions

codePage is less than zero.

Remarks

This constructor is protected; derived classes override it.

You call this constructor from a derived class to control the fallback encoding and decoding strategies. The Encoding class constructors create read-only encoding objects that don't allow encoder or decoder fallback to be set after the object is created.

If either encoderFallback or decoderFallback is null, best-fit fallback is used as the corresponding fallback strategy.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0