C# Console WriteLine(String, Object[]) Array

Description

Console WriteLine(String, Object[]) writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information.

Syntax

Console.WriteLine(String, Object[]) has the following syntax.


[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)]
public static void WriteLine(
  string format,/*from w w w  . jav a  2  s .  co  m*/
  params Object[] arg
)

Parameters

Console.WriteLine(String, Object[]) has the following parameters.

  • format - A composite format string (see Remarks).
  • arg - An array of objects to write using format.

Returns

Console.WriteLine(String, Object[]) method returns

Example

The following example demonstrates the standard formatting specifiers for numbers, dates , and enumerations.


using System;/*w  ww.j  av a  2s .c  o  m*/
class Sample 
{
    enum Color {Yellow = 1, Blue, Green};
    static DateTime thisDate = DateTime.Now;

    public static void Main() 
    {

    Console.WriteLine("Standard Numeric Format Specifiers");
    Console.WriteLine(
        "(C) Currency: . . . . . . . . {0:C}\n" +
        "(D) Decimal:. . . . . . . . . {0:D}\n" +
        "(E) Scientific: . . . . . . . {1:E}\n" +
        "(F) Fixed point:. . . . . . . {1:F}\n" +
        "(G) General:. . . . . . . . . {0:G}\n" +
        "    (default):. . . . . . . . {0} (default = 'G')\n" +
        "(N) Number: . . . . . . . . . {0:N}\n" +
        "(P) Percent:. . . . . . . . . {1:P}\n" +
        "(R) Round-trip: . . . . . . . {1:R}\n" +
        "(X) Hexadecimal:. . . . . . . {0:X}\n",
        new object[]{ -123, -123.45f}); 
       
    }
}




















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version