Export (0) Print
Expand All

Console.Write Method (Boolean)

.NET Framework 1.1

Writes the text representation of the specified Boolean value to the standard output stream.

[Visual Basic]
Overloads Public Shared Sub Write( _
   ByVal value As Boolean _
)
[C#]
public static void Write(
 bool value
);
[C++]
public: static void Write(
 bool value
);
[JScript]
public static function Write(
   value : Boolean
);

Parameters

value
The value to write.

Exceptions

Exception Type Condition
IOException An I/O error occurred.

Remarks

The text representation of value is produced by calling Boolean.ToString, which outputs either Boolean.TrueString or Boolean.FalseString.

Example

The following code sample illustrates the use of Write:

[Visual Basic] 
Public Class FormatConverter
   Public Shared Sub Main()
      Dim lineInput As String
      lineInput = Console.ReadLine()
      While Not lineInput Is Nothing
         Dim fields() As String = lineInput.Split(ControlChars.Tab)
         Dim isFirstField As Boolean = True
         Dim item As String
         For Each item In  fields
            If isFirstField Then
               isFirstField = False
            Else
               Console.Write(",")
            End If
            ' If the field represents a boolean, replace with a numeric representation.
            Try
               Console.Write(Convert.ToByte(Convert.ToBoolean(item)))
            Catch
               Console.Write(item)
            End Try
         Next item
         Console.WriteLine()
         lineInput = Console.ReadLine()
      End While
   End Sub 'Main
End Class 'FormatConverter

[C#] 
public class FormatConverter {
    public static void Main(string[] args) {
        string lineInput;
        while ((lineInput = Console.ReadLine()) != null) {
            string[] fields = lineInput.Split(new char[] {'\t'});
            bool isFirstField = true;
            foreach(string item in fields) {
                if (isFirstField)
                    isFirstField = false;
                else
                    Console.Write(',');
                // If the field represents a boolean, replace with a numeric representation.
                try {
                    Console.Write(Convert.ToByte(Convert.ToBoolean(item)));
                }
                catch(FormatException) {
                    Console.Write(item);
                }
            }
            Console.WriteLine();
        }
    }
}

[C++] 

int main() {
   String* lineInputArr __gc[] = {S"1    2.2    hello    TRUE", S"2    5.22    bye    FALSE", S"3    6.38    see ya'    TRUE"};

   for( Int32 i = 0; i < 3; i++) {
      String* lineInput = lineInputArr->GetValue(i)->ToString();
      String* aChar = "\t";
      String* fields __gc[] = lineInput->Split(aChar->ToCharArray());
      Boolean isFirstField = true;
      for (Int32 i = 0; i < fields->Length; i++) {
         if (isFirstField)
            isFirstField = false;
         else
            Console::Write(S",");

         // If the field represents a boolean, replace with a numeric representation.
         try {
            Console::Write(Convert::ToByte(Convert::ToBoolean(fields[i])));
         }
         catch(FormatException*) {
            Console::Write(fields[i]);
         }
      }
      Console::WriteLine();
   }
}


[JScript] 
var lineInput : String;
while ((lineInput = Console.ReadLine()) != null) {
    var fields : String[] = lineInput.Split(char[](['\t']));
    var isFirstField : Boolean = true;
    for(var i in fields) {
        var item = fields[i];
        if (isFirstField)
            isFirstField = false;
        else
            Console.Write(',');
        // If the field represents a boolean, replace with a numeric representation.
        try {
            Console.Write(Convert.ToByte(Convert.ToBoolean(item)));
        }
        catch(FormatException) {
            Console.Write(item);
        }
    }
    Console.WriteLine();
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Console Class | Console Members | System Namespace | Console.Write Overload List | Read | ReadLine | WriteLine

Show:
© 2014 Microsoft