次の方法で共有


Convert.ToString メソッド (Boolean)

指定したブール値を、それと等価な String 形式に変換します。

Overloads Public Shared Function ToString( _
   ByVal value As Boolean _) As String
[C#]
public static string ToString(boolvalue);
[C++]
public: static String* ToString(boolvalue);
[JScript]
public static function ToString(
   value : Boolean) : String;

パラメータ

  • value
    Boolean 値。

戻り値

value の値と等価な String

解説

この実装は、 Boolean.ToString と同じです。

使用例

[Visual Basic, C#, C++] ToString を使用して、 BooleanString に変換する方法については、次のコード例を参照してください。

 
Public Sub ConvertStringBoolean(ByVal stringVal As String)

    Dim boolVal As Boolean = False

    Try
        boolVal = System.Convert.ToBoolean(stringVal)
        If boolVal Then
            System.Console.WriteLine( _
                "String is equal to System.Boolean.TrueString.")
        Else
            System.Console.WriteLine( _
                "String is equal to System.Boolean.FalseString.")
        End If
    Catch exception As System.FormatException
        System.Console.WriteLine( _
            "The string must equal System.Boolean.TrueString " + _
            "or System.Boolean.FalseString.")
    End Try

    ' A conversion from bool to string will always succeed.
    stringVal = System.Convert.ToString(boolVal)
    System.Console.WriteLine("{0} as a String is {1}", _
                              boolVal, stringVal)
End Sub

[C#] 
public void ConvertStringBoolean(string stringVal) {
    
    bool boolVal = false;

    try {
        boolVal = System.Convert.ToBoolean(stringVal);
        if (boolVal) {
            System.Console.WriteLine(
                "String was equal to System.Boolean.TrueString.");
        }
        else {
            System.Console.WriteLine(
                "String was equal to System.Boolean.FalseString.");
        }
    }
    catch (System.FormatException){
        System.Console.WriteLine(
            "The string must equal System.Boolean.TrueString " +
            "or System.Boolean.FalseString.");
    }

    // A conversion from bool to string will always succeed.
    stringVal = System.Convert.ToString(boolVal);
    System.Console.WriteLine("{0} as a string is {1}",
        boolVal, stringVal);
}

[C++] 

   void ConvertStringBoolean(String* stringVal)
   {
      bool boolVal = false;

      try {
         boolVal = System::Convert::ToBoolean(stringVal);
         if (boolVal) {
            System::Console::WriteLine(S"String was equal to System::Boolean::TrueString.");
         } else {
            System::Console::WriteLine(S"String was equal to System::Boolean::FalseString.");
         }
      } catch (System::FormatException*) {
         System::Console::WriteLine(S"The String* must equal System::Boolean::TrueString or System::Boolean::FalseString.");
      }

      // A conversion from bool to String* will always succeed.
      stringVal = System::Convert::ToString(boolVal);
      System::Console::WriteLine(S" {0} as a String* is {1}",
         __box(boolVal), stringVal);
   }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Convert クラス | Convert メンバ | System 名前空間 | Convert.ToString オーバーロードの一覧