Export (0) Print
Expand All

Console.Write Method

Writes the specified information to the standard output stream.

Overload List

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

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

Writes the specified Unicode character value to the standard output stream.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Char)
[C#] public static void Write(char);
[C++] public: static void Write(__wchar_t);
[JScript] public static function Write(Char);

Writes the specified array of Unicode characters to the standard output stream.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Char())
[C#] public static void Write(char[]);
[C++] public: static void Write(__wchar_t __gc[]);
[JScript] public static function Write(Char[]);

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

[Visual Basic] Overloads Public Shared Sub Write(Decimal)
[C#] public static void Write(decimal);
[C++] public: static void Write(Decimal);
[JScript] public static function Write(Decimal);

Writes the text representation of the specified double-precision floating-point value to the standard output stream.

[Visual Basic] Overloads Public Shared Sub Write(Double)
[C#] public static void Write(double);
[C++] public: static void Write(double);
[JScript] public static function Write(double);

Writes the text representation of the specified 32-bit signed integer value to the standard output stream.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Integer)
[C#] public static void Write(int);
[C++] public: static void Write(int);
[JScript] public static function Write(int);

Writes the text representation of the specified 64-bit signed integer value to the standard output stream.

[Visual Basic] Overloads Public Shared Sub Write(Long)
[C#] public static void Write(long);
[C++] public: static void Write(__int64);
[JScript] public static function Write(long);

Writes the text representation of the specified object to the standard output stream.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Object)
[C#] public static void Write(object);
[C++] public: static void Write(Object*);
[JScript] public static function Write(Object);

Writes the text representation of the specified single-precision floating-point value to the standard output stream.

[Visual Basic] Overloads Public Shared Sub Write(Single)
[C#] public static void Write(float);
[C++] public: static void Write(float);
[JScript] public static function Write(float);

Writes the specified string value to the standard output stream.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String)
[C#] public static void Write(string);
[C++] public: static void Write(String*);
[JScript] public static function Write(String);

Writes the text representation of the specified 32-bit unsigned integer value to the standard output stream. This method is not CLS-compliant.

[Visual Basic] Overloads Public Shared Sub Write(UInt32)
[C#] public static void Write(uint);
[C++] public: static void Write(unsigned int);
[JScript] public static function Write(UInt32);

Writes the text representation of the specified 64-bit unsigned integer value to the standard output stream. This method is not CLS-compliant.

[Visual Basic] Overloads Public Shared Sub Write(UInt64)
[C#] public static void Write(ulong);
[C++] public: static void Write(unsigned __int64);
[JScript] public static function Write(UInt64);

Writes the specified object to the standard output stream using the specified format information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String, Object)
[C#] public static void Write(string, object);
[C++] public: static void Write(String*, Object*);
[JScript] public static function Write(String, Object);

Writes the specified array of objects to the standard output stream using the specified format information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String, ParamArray Object())
[C#] public static void Write(string, params object[]);
[C++] public: static void Write(String*, Object[]);
[JScript] public static function Write(String, Object[]);

Writes the specified subarray of Unicode characters to the standard output stream.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Char(), Integer, Integer)
[C#] public static void Write(char[], int, int);
[C++] public: static void Write(__wchar_t __gc[], int, int);
[JScript] public static function Write(Char[], int, int);

Writes the specified objects to the standard output stream using the specified format information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String, Object, Object)
[C#] public static void Write(string, object, object);
[C++] public: static void Write(String*, Object*, Object*);
[JScript] public static function Write(String, Object, Object);

Writes the specified objects to the standard output stream using the specified format information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String, Object, Object, Object)
[C#] public static void Write(string, object, object, object);
[C++] public: static void Write(String*, Object*, Object*, Object*);
[JScript] public static function Write(String, Object, Object, Object);

[C++] Writes the specified objects and variable length parameter list to the standard output stream using the specified format information. This method is not CLS-compliant.

[C++] public: static void Write(String*, Object*, Object*, Object*, Object*, ...);

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();
}

See Also

Console Class | Console Members | System Namespace

Show:
© 2014 Microsoft