UTF8Encoding.GetMaxByteCount メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > UTF8Encoding.GetMaxByteCount メソッドの意味・解説 

UTF8Encoding.GetMaxByteCount メソッド

指定した文字数をエンコードすることによって生成される最大バイト数を計算します。

名前空間: System.Text
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overrides Function
 GetMaxByteCount ( _
    charCount As Integer _
) As Integer
Dim instance As UTF8Encoding
Dim charCount As Integer
Dim returnValue As Integer

returnValue = instance.GetMaxByteCount(charCount)
public override int GetMaxByteCount (
    int charCount
)
public:
virtual int GetMaxByteCount (
    int charCount
) override
public int GetMaxByteCount (
    int charCount
)
public override function GetMaxByteCount (
    charCount : int
) : int

パラメータ

charCount

エンコードする文字数。

戻り値
指定した文字数をエンコードすることによって生成される最大バイト数。

例外例外
例外の種類条件

ArgumentOutOfRangeException

charCount が 0 未満です。

または

結果の文字数が、int として返すことのできる最大数を超えています。

解説解説

GetBytes が生成したバイトを格納するために必要な正確な配列サイズを計算するには、GetByteCount を使用します。最大配列サイズを計算するには、GetMaxByteCount を使用します。通常、GetMaxByteCount メソッドの方が高速に実行されるのに対し、GetByteCount メソッドの方が使用メモリが少なくて済みます。

使用例使用例

次の例は、指定した文字数をエンコードするために必要な最大バイト数を、GetMaxByteCount メソッドを使用して計算する方法を示しています。

Imports System
Imports System.Text

Class UTF8EncodingExample
    
    Public Shared Sub Main()
        Dim utf8 As New
 UTF8Encoding()
        Dim charCount As Integer
 = 2
        Dim maxByteCount As Integer
 = utf8.GetMaxByteCount(charCount)
        Console.WriteLine( _
            "Maximum of {0} bytes needed to encode {1} characters.",
 _
            maxByteCount, _
            charCount _
        )
    End Sub 'Main
End Class 'UTF8EncodingExample
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main()
 {
        UTF8Encoding utf8 = new UTF8Encoding();
        int charCount = 2;
        int maxByteCount = utf8.GetMaxByteCount(charCount);
        Console.WriteLine(
            "Maximum of {0} bytes needed to encode {1} characters.",
            maxByteCount,
            charCount
        );
    }
}
using namespace System;
using namespace System::Text;
int main()
{
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   int charCount = 2;
   int maxByteCount = utf8->GetMaxByteCount( charCount );
   Console::WriteLine( "Maximum of {0} bytes needed to encode {1} characters.",
 maxByteCount, charCount );
}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[]
 args)
    {
        UTF8Encoding utf8 = new UTF8Encoding();
        int charCount = 2;
        int maxByteCount = utf8.GetMaxByteCount(charCount);

        Console.WriteLine(
            "Maximum of {0} bytes needed to encode {1} characters.", 
            String.valueOf(maxByteCount), String.valueOf(charCount));
    } //main
} //UTF8EncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UTF8Encoding クラス
UTF8Encoding メンバ
System.Text 名前空間
GetBytes
GetByteCount
GetEncoder


このページでは「.NET Framework クラス ライブラリ リファレンス」からUTF8Encoding.GetMaxByteCount メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からUTF8Encoding.GetMaxByteCount メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からUTF8Encoding.GetMaxByteCount メソッド を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

UTF8Encoding.GetMaxByteCount メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



UTF8Encoding.GetMaxByteCount メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS