Op Englesch liesen Editéieren

Deelen iwwer


Decoder.GetCharCount Method

Definition

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes.

Overloads

GetCharCount(ReadOnlySpan<Byte>, Boolean)

When overridden in a derived class, calculates the number of characters produced by decoding the sequence of bytes in the span. A parameter indicates whether to clear the internal state of the decoder after the calculation.

GetCharCount(Byte*, Int32, Boolean)

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. A parameter indicates whether to clear the internal state of the decoder after the calculation.

GetCharCount(Byte[], Int32, Int32)

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

GetCharCount(Byte[], Int32, Int32, Boolean)

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. A parameter indicates whether to clear the internal state of the decoder after the calculation.

GetCharCount(ReadOnlySpan<Byte>, Boolean)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

When overridden in a derived class, calculates the number of characters produced by decoding the sequence of bytes in the span. A parameter indicates whether to clear the internal state of the decoder after the calculation.

C#
public virtual int GetCharCount(ReadOnlySpan<byte> bytes, bool flush);

Parameters

bytes
ReadOnlySpan<Byte>

A byte span to decode.

flush
Boolean

true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Remarks

This method does not affect the state of the decoder.

To calculate the exact buffer size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

GetCharCount(Byte*, Int32, Boolean)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

Important

This API is not CLS-compliant.

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. A parameter indicates whether to clear the internal state of the decoder after the calculation.

C#
[System.CLSCompliant(false)]
public virtual int GetCharCount(byte* bytes, int count, bool flush);
C#
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetCharCount(byte* bytes, int count, bool flush);
C#
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual int GetCharCount(byte* bytes, int count, bool flush);

Parameters

bytes
Byte*

A pointer to the first byte to decode.

count
Int32

The number of bytes to decode.

flush
Boolean

true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Attributes

Exceptions

bytes is null (Nothing in Visual Basic .NET).

count is less than zero.

A fallback occurred (for more information, see Character Encoding in .NET)

-and-

Fallback is set to DecoderExceptionFallback.

Remarks

This method does not affect the state of the decoder.

To calculate the exact array size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

See also

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 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 2.0, 2.1

GetCharCount(Byte[], Int32, Int32)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

C#
public abstract int GetCharCount(byte[] bytes, int index, int count);

Parameters

bytes
Byte[]

The byte array containing the sequence of bytes to decode.

index
Int32

The index of the first byte to decode.

count
Int32

The number of bytes to decode.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Exceptions

bytes is null (Nothing).

index or count is less than zero.

-or-

index and count do not denote a valid range in bytes.

A fallback occurred (for more information, see Character Encoding in .NET)

-and-

Fallback is set to DecoderExceptionFallback.

Examples

The following code example demonstrates how to use the GetCharCount method to calculate the number of characters required to decode the specified range of bytes in the array.

C#
using System;
using System.Text;

class DecoderExample {
    public static void Main() {
        Byte[] bytes = new Byte[] {
            85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0
        };

        Decoder uniDecoder = Encoding.Unicode.GetDecoder();
        int charCount = uniDecoder.GetCharCount(bytes, 0, bytes.Length);
        Console.WriteLine(
            "{0} characters needed to decode bytes.", charCount
        );
    }
}

/* This code example produces the following output.

7 characters needed to decode bytes.

*/

Remarks

This method does not affect the state of the decoder.

To calculate the exact array size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

See also

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.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, 10
.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

GetCharCount(Byte[], Int32, Int32, Boolean)

Source:
Decoder.cs
Source:
Decoder.cs
Source:
Decoder.cs

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. A parameter indicates whether to clear the internal state of the decoder after the calculation.

C#
public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush);
C#
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush);

Parameters

bytes
Byte[]

The byte array containing the sequence of bytes to decode.

index
Int32

The index of the first byte to decode.

count
Int32

The number of bytes to decode.

flush
Boolean

true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.

Attributes

Exceptions

bytes is null (Nothing).

index or count is less than zero.

-or-

index and count do not denote a valid range in bytes.

A fallback occurred (for more information, see Character Encoding in .NET)

-and-

Fallback is set to DecoderExceptionFallback.

Remarks

This method does not affect the state of the decoder.

To calculate the exact array size that GetChars requires to store the resulting characters, the application should use GetCharCount.

If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.

See also

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.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, 10
.NET Framework 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