Calculates the number of bytes produced by encoding a set of characters : Encoder « Development Class « C# / C Sharp






Calculates the number of bytes produced by encoding a set of characters

 

using System;
using System.Text;

class EncoderExample {
    public static void Main() {
        // Unicode characters.
        Char[] chars = new Char[] {
            '\u03a3'  // Sigma
        };

        Encoder uniEncoder = Encoding.Unicode.GetEncoder();
        int byteCount = uniEncoder.GetByteCount(chars, 0, chars.Length, true);
        Console.WriteLine(byteCount);
    }
}

   
  








Related examples in the same category

1.Encoder converts a set of characters into a sequence of bytes.
2.Create a new instance of the Encoder class
3.Encode a set of characters from the specified character array