Console.Write Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Schreibt die Textdarstellung des angegebenen booleschen Werts oder der angegebenen booleschen Werte in den Standardausgabestream.
Überlädt
Write(String, Object, Object, Object, Object) |
Schreibt die Textdarstellung der angegebenen Objekte und der Parameterliste von variabler Länge unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream. |
Write(String, Object, Object, Object) |
Schreibt die Textdarstellung der angegebenen Objekte unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream. |
Write(Char[], Int32, Int32) |
Schreibt das angegebene Unterarray von Unicode-Zeichen in den Standardausgabestream. |
Write(String, ReadOnlySpan<Object>) | |
Write(String, Object[]) |
Schreibt die Textdarstellung des angegebenen Arrays von Objekten unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream. |
Write(String, Object) |
Schreibt die Textdarstellung des angegebenen Objekts unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream. |
Write(UInt64) |
Schreibt die Textdarstellung der angegebenen 64-Bit-Ganzzahl ohne Vorzeichen in den Standardausgabestream. |
Write(UInt32) |
Schreibt die Textdarstellung der angegebenen 32-Bit-Ganzzahl ohne Vorzeichen in den Standardausgabestream. |
Write(String) |
Schreibt die angegebene Zeichenfolge in den Standardausgabestream. |
Write(String, Object, Object) |
Schreibt die Textdarstellung der angegebenen Objekte unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream. |
Write(Object) |
Schreibt die Textdarstellung des angegebenen Objekts in den Standardausgabestream. |
Write(Single) |
Schreibt die Textdarstellung der angegebenen Gleitkommazahl mit einfacher Genauigkeit in den Standardausgabestream. |
Write(Char) |
Schreibt das angegebene Unicode-Zeichen in den Standardausgabestream. |
Write(Char[]) |
Schreibt das angegebene Array von Unicode-Zeichen in den Standardausgabestream. |
Write(Boolean) |
Schreibt die Textdarstellung des angegebenen booleschen Werts in den Standardausgabestream. |
Write(Double) |
Schreibt die Textdarstellung der angegebenen Gleitkommazahl mit doppelter Genauigkeit in den Standardausgabestream. |
Write(Int32) |
Schreibt die Textdarstellung der angegebenen 32-Bit-Ganzzahl mit Vorzeichen in den Standardausgabestream. |
Write(Int64) |
Schreibt die Textdarstellung der angegebenen 64-Bit-Ganzzahl mit Vorzeichen in den Standardausgabestream. |
Write(Decimal) |
Schreibt die Textdarstellung des angegebenen Decimal-Werts in den Standardausgabestream. |
Write(String, Object, Object, Object, Object)
Wichtig
Diese API ist nicht CLS-kompatibel.
Schreibt die Textdarstellung der angegebenen Objekte und der Parameterliste von variabler Länge unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream.
public:
static void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2, System::Object ^ arg3);
[System.CLSCompliant(false)]
public static void Write (string format, object arg0, object arg1, object arg2, object arg3);
[<System.CLSCompliant(false)>]
static member Write : string * obj * obj * obj * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object, arg1 As Object, arg2 As Object, arg3 As Object)
Parameter
- format
- String
Eine kombinierte Formatzeichenfolge.
- arg0
- Object
Das erste mit format
zu schreibende Objekt.
- arg1
- Object
Das zweite mit format
zu schreibende Objekt.
- arg2
- Object
Das dritte mit format
zu schreibende Objekt.
- arg3
- Object
Das vierte mit format
zu schreibende Objekt.
- Attribute
Ausnahmen
E/A-Fehler
format
ist null
.
Die Formatangabe in format
ist ungültig.
Beispiele
Im folgenden Beispiel wird die Verwendung von Variablenparametern mit der Write(String, Object, Object, Object, Object) -Methode veranschaulicht. Die -Methode wird mit einer zusammengesetzten Formatzeichenfolge und fünf Formatelementen aufgerufen.
using namespace System;
//void main(array<System::String ^> ^args)
void main()
{
DateTime dateRecorded(2009, 6, 15);
DateTime startTime(1, 1, 1, 0, 30, 0);
TimeSpan interval(12, 0, 0);
Double temperature1 = 52.8;
Double temperature2 = 63.5;
Console::Write("Date: {0:d}:\n Temperature at {1:t}: {2}\n Temperature at {3:t}: {4}\n",
dateRecorded, startTime, temperature1,
startTime.Add(interval), temperature2);
Console::ReadLine();
}
// The example displays the following output:
// Date: 6/15/2009:
// Temperature at 12:30 AM: 52.8
// Temperature at 12:30 PM: 63.5
Hinweise
Hinweis
Diese API ist nicht CLS-kompatibel. Die CLS-kompatible Alternative ist Console.Write(String, Object[]). Die C#- und Visual Basic-Compiler lösen einen Aufruf dieser Methode automatisch als Aufruf von auf Console.Write(String, Object[]).
Diese Methode verwendet die zusammengesetzte Formatierungsfunktion von .NET, um den Wert eines Objekts in seine Textdarstellung zu konvertieren und diese Darstellung in eine Zeichenfolge einzubetten. Die resultierende Zeichenfolge wird in den Ausgabedatenstrom geschrieben.
Der format
Parameter besteht aus null oder mehr Textausführungen, die mit null oder mehr indizierten Platzhaltern, sogenannten Formatelementen, vermischt sind, die einem Objekt in der Parameterliste dieser Methode entsprechen. Der Formatierungsprozess ersetzt jedes Formatelement durch die Textdarstellung des Werts des entsprechenden Objekts.
Die Syntax eines Formatelements ist {
index[,
alignment][:
formatString]}
, der einen obligatorischen Index, die optionale Länge und Ausrichtung des formatierten Texts sowie eine optionale Zeichenfolge von Formatbezeichnerzeichen angibt, die bestimmen, wie der Wert des entsprechenden Objekts formatiert wird.
.NET bietet umfangreiche Formatierungsunterstützung, die in den folgenden Formatierungsthemen ausführlicher beschrieben wird.
Weitere Informationen zur zusammengesetzten Formatierungsfunktion, die von Methoden wie Format, AppendFormatund einigen Überladungen von WriteLineunterstützt wird, finden Sie unter Zusammengesetzte Formatierung.
Weitere Informationen zu numerischen Formatbezeichnern finden Sie unter Numerische Standardformatzeichenfolgen und benutzerdefinierte numerische Formatzeichenfolgen.
Weitere Informationen zu Datums- und Uhrzeitformatbezeichnern finden Sie unter Standard-Datums- und Uhrzeitformatzeichenfolgen und benutzerdefinierte Datums- und Uhrzeitformatzeichenfolgen.
Weitere Informationen zu Enumerationsformatbezeichnern finden Sie unter Enumerationsformatzeichenfolgen.
Weitere Informationen zur Formatierung finden Sie unter Formatierungstypen.
Hinweise für Aufrufer
Diese Methode ist mit dem vararg
Schlüsselwort (keyword) gekennzeichnet, was bedeutet, dass sie eine variable Anzahl von Parametern unterstützt. Die Methode kann von Visual C++ aus aufgerufen werden, kann aber nicht über C#- oder Visual Basic-Code aufgerufen werden. Die C#- und Visual Basic-Compiler lösen Aufrufe von Write(String, Object, Object, Object, Object) als Aufrufe von auf Write(String, Object[]).
Weitere Informationen
Gilt für:
Write(String, Object, Object, Object)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung der angegebenen Objekte unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream.
public:
static void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public static void Write (string format, object? arg0, object? arg1, object? arg2);
public static void Write (string format, object arg0, object arg1, object arg2);
static member Write : string * obj * obj * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object, arg1 As Object, arg2 As Object)
Parameter
- format
- String
Eine kombinierte Formatzeichenfolge.
- arg0
- Object
Das erste mit format
zu schreibende Objekt.
- arg1
- Object
Das zweite mit format
zu schreibende Objekt.
- arg2
- Object
Das dritte mit format
zu schreibende Objekt.
Ausnahmen
E/A-Fehler
format
ist null
.
Die Formatangabe in format
ist ungültig.
Beispiele
Im folgenden Beispiel werden die Standardformatbezeichner für Zahlen, Datumsangaben und Enumerationen mithilfe der WriteLine
-Methode veranschaulicht.
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using namespace System;
public enum class Color {Yellow = 1, Blue, Green};
int main()
{
DateTime thisDate = DateTime::Now;
Console::Clear();
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f);
// Format the current date in various ways.
Console::WriteLine("Standard DateTime Format Specifiers");
Console::WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console::WriteLine("Standard Enumeration Format Specifiers");
Console::WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color::Green);
};
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
Console.Clear();
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
open System
type Color =
| Yellow = 1
| Blue = 2
| Green = 3
let thisDate = DateTime.Now
Console.Clear()
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f)
// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate)
// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green)
// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
// (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
// (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
// (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Diese Methode verwendet die zusammengesetzte Formatierungsfunktion von .NET, um den Wert eines Objekts in seine Textdarstellung zu konvertieren und diese Darstellung in eine Zeichenfolge einzubetten. Die resultierende Zeichenfolge wird in den Ausgabedatenstrom geschrieben.
Der format
Parameter besteht aus null oder mehr Textausführungen, die mit null oder mehr indizierten Platzhaltern, sogenannten Formatelementen, vermischt sind, die einem Objekt in der Parameterliste dieser Methode entsprechen. Der Formatierungsprozess ersetzt jedes Formatelement durch die Textdarstellung des Werts des entsprechenden Objekts.
Die Syntax eines Formatelements ist {
index[,
alignment][:
formatString]}
, der einen obligatorischen Index, die optionale Länge und Ausrichtung des formatierten Texts sowie eine optionale Zeichenfolge von Formatbezeichnerzeichen angibt, die bestimmen, wie der Wert des entsprechenden Objekts formatiert wird.
.NET bietet umfangreiche Formatierungsunterstützung, die in den folgenden Formatierungsthemen ausführlicher beschrieben wird.
Weitere Informationen zur zusammengesetzten Formatierungsfunktion, die von Methoden wie Format, AppendFormatund einigen Überladungen von WriteLineunterstützt wird, finden Sie unter Zusammengesetzte Formatierung.
Weitere Informationen zu numerischen Formatbezeichnern finden Sie unter Numerische Standardformatzeichenfolgen und benutzerdefinierte numerische Formatzeichenfolgen.
Weitere Informationen zu Datums- und Uhrzeitformatbezeichnern finden Sie unter Standard-Datums- und Uhrzeitformatzeichenfolgen und benutzerdefinierte Datums- und Uhrzeitformatzeichenfolgen.
Weitere Informationen zu Enumerationsformatbezeichnern finden Sie unter Enumerationsformatzeichenfolgen.
Weitere Informationen zur Formatierung finden Sie unter Formatierungstypen.
Weitere Informationen
Gilt für:
Write(Char[], Int32, Int32)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt das angegebene Unterarray von Unicode-Zeichen in den Standardausgabestream.
public:
static void Write(cli::array <char> ^ buffer, int index, int count);
public static void Write (char[] buffer, int index, int count);
static member Write : char[] * int * int -> unit
Public Shared Sub Write (buffer As Char(), index As Integer, count As Integer)
Parameter
- buffer
- Char[]
Ein Array von Unicode-Zeichen.
- index
- Int32
Die Anfangsposition in buffer
.
- count
- Int32
Die Anzahl der zu schreibenden Zeichen.
Ausnahmen
buffer
ist null
.
index
oder count
ist kleiner als 0.
index
plus count
geben eine Position an, die nicht innerhalb von buffer
liegt.
E/A-Fehler
Hinweise
Diese Methode schreibt count
Zeichen ab position index
von buffer
bis zum Standardausgabedatenstrom.
Weitere Informationen
Gilt für:
Write(String, ReadOnlySpan<Object>)
public:
static void Write(System::String ^ format, ReadOnlySpan<System::Object ^> arg);
public static void Write (string format, scoped ReadOnlySpan<object?> arg);
static member Write : string * ReadOnlySpan<obj> -> unit
Public Shared Sub Write (format As String, arg As ReadOnlySpan(Of Object))
Parameter
- format
- String
- arg
- ReadOnlySpan<Object>
Gilt für:
Write(String, Object[])
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung des angegebenen Arrays von Objekten unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream.
public:
static void Write(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public static void Write (string format, params object?[]? arg);
public static void Write (string format, params object[] arg);
static member Write : string * obj[] -> unit
Public Shared Sub Write (format As String, ParamArray arg As Object())
Parameter
- format
- String
Eine kombinierte Formatzeichenfolge.
- arg
- Object[]
Ein mit format
zu schreibendes Array von Objekten.
Ausnahmen
E/A-Fehler
format
oder arg
ist null
.
Die Formatangabe in format
ist ungültig.
Beispiele
Im folgenden Beispiel wird eine Person
Klasse mit einer Reihe von Eigenschaften definiert, die Informationen zu einer Person bereitstellen. Die - GetDescription
Methode gibt ein Array zurück, das alle Eigenschaftswerte mit Ausnahme eines enthält. Im Beispiel wird dann das von der GetDescription
-Methode zurückgegebene Array verwendet, um die Werte des Person-Objekts anzuzeigen.
using System;
public class Person
{
public String Name { get; set; }
public DateTime BirthDate { get; set; }
public Double Height { get; set; }
public Double Weight { get; set; }
public Char Gender { get; set; }
public String Remarks { get; set; }
public object[] GetDescription()
{
return new object[] { Name, Gender, Height, Weight, BirthDate};
}
}
public class Example
{
public static void Main()
{
var p1 = new Person() { Name = "John", Gender = 'M',
BirthDate = new DateTime(1992, 5, 10),
Height = 73.5, Weight = 207 };
p1.Remarks = "Client since 1/3/2012";
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ",
p1.GetDescription());
if (String.IsNullOrEmpty(p1.Remarks))
Console.WriteLine();
else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth ?
"\n " : "");
}
}
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
open System
type Person =
{ Name: string
BirthDate: DateOnly
Height: double
Weight: double
Gender: char
Remarks: string }
member this.GetDescription(): obj [] =
[| this.Name; this.Gender; this.Height; this.Weight; this.BirthDate |]
let p1 =
{ Name = "John"
Gender = 'M'
BirthDate = DateOnly(1992, 5, 10)
Height = 73.5
Weight = 207
Remarks = "Client since 1/3/2012" }
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ", p1.GetDescription())
if String.IsNullOrEmpty p1.Remarks then
Console.WriteLine()
else
Console.WriteLine $"""{if Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth then "\n " else ""}Remarks: {p1.Remarks}"""
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Public Class Person
Public Property Name As String
Public Property BirthDate As DateTime
Public Property Height As Double
Public Property Weight As Double
Public Property Gender As Char
Public Property Remarks As String
Public Function GetDescription() As Object()
Return { Name, Gender, Height, Weight, BirthDate}
End Function
End Class
Module Example
Public Sub Main()
Dim p1 As New Person() With { .Name = "John", .Gender = "M"c,
.BirthDate = New DateTime(1992, 5, 10),
.Height = 73.5, .Weight = 207 }
p1.Remarks = "Client since 1/3/2012"
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ",
p1.GetDescription())
If String.IsNullOrEmpty(p1.Remarks) Then
Console.WriteLine()
Else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
If(Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth,
vbCrLf + " ", ""))
End If
End Sub
End Module
' The example displays the following output:
' John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Beachten Sie, dass das Beispiel die Write(String, Object[]) -Methode und nicht die WriteLine(String, Object[]) -Methode aufruft, da versucht wird, den Wert der Person.Remarks
Eigenschaft in derselben Zeile anzuzeigen. Zu diesem Zweck wird der Wert der CursorLeft Eigenschaften und WindowWidth untersucht, um zu ermitteln, ob genügend Platz für die Bemerkung vorhanden ist. Falls vorhanden, wird die Zeile angezeigt. Andernfalls wird eine Zeile geschrieben, drei Leerzeichen eingerückt und die Bemerkung angezeigt.
Das folgende Beispiel ist identisch mit dem ersten, mit dem Unterschied, dass es eine Liste mit fünf Elementen als arg
Argument anstelle eines Parameterarrays bereitstellt.
using System;
public class Person
{
public String Name { get; set; }
public DateTime BirthDate { get; set; }
public Double Height { get; set; }
public Double Weight { get; set; }
public Char Gender { get; set; }
public String Remarks { get; set; }
public object[] GetDescription()
{
return new object[] { Name, Gender, Height, Weight, BirthDate};
}
}
public class Example
{
public static void Main()
{
var p1 = new Person() { Name = "John", Gender = 'M',
BirthDate = new DateTime(1992, 5, 10),
Height = 73.5, Weight = 207 };
p1.Remarks = "Client since 1/3/2012";
Console.Write("{0}: {1}, born {2:d} Height {3} inches, Weight {4} lbs ",
p1.Name, p1.Gender, p1.BirthDate, p1.Height, p1.Weight);
if (String.IsNullOrEmpty(p1.Remarks))
Console.WriteLine();
else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth ?
"\n " : "");
}
}
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
open System
type Person =
{ Name: string
BirthDate: DateOnly
Height: double
Weight: double
Gender: char
Remarks: string }
member this.GetDescription(): obj [] =
[| this.Name; this.Gender; this.Height; this.Weight; this.BirthDate |]
let p1 =
{ Name = "John"
Gender = 'M'
BirthDate = DateOnly(1992, 5, 10)
Height = 73.5
Weight = 207
Remarks = "Client since 1/3/2012" }
printf $"{p1.Name}: {p1.Gender}, born {p1.BirthDate:d} Height {p1.Height} inches, Weight {p1.Weight} lbs "
if String.IsNullOrEmpty p1.Remarks then
Console.WriteLine()
else
Console.WriteLine $"""{if Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth then "\n " else ""}Remarks: {p1.Remarks}"""
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Public Class Person
Public Property Name As String
Public Property BirthDate As DateTime
Public Property Height As Double
Public Property Weight As Double
Public Property Gender As Char
Public Property Remarks As String
Public Function GetDescription() As Object()
Return { Name, Gender, Height, Weight, BirthDate}
End Function
End Class
Module Example
Public Sub Main()
Dim p1 As New Person() With { .Name = "John", .Gender = "M"c,
.BirthDate = New DateTime(1992, 5, 10),
.Height = 73.5, .Weight = 207 }
p1.Remarks = "Client since 1/3/2012"
Console.Write("{0}: {1}, born {2:d} Height {3} inches, Weight {4} lbs ",
p1.Name, p1.Gender, p1.BirthDate, p1.Height, p1.Weight)
If String.IsNullOrEmpty(p1.Remarks) Then
Console.WriteLine()
Else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
If(Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth,
vbCrLf + " ", ""))
End If
End Sub
End Module
' The example displays the following output:
' John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Hinweise
Diese Methode verwendet die zusammengesetzte Formatierungsfunktion von .NET, um den Wert eines Objekts in seine Textdarstellung zu konvertieren und diese Darstellung in eine Zeichenfolge einzubetten. Die resultierende Zeichenfolge wird in den Ausgabedatenstrom geschrieben.
Der format
Parameter besteht aus null oder mehr Textausführungen, die mit null oder mehr indizierten Platzhaltern, sogenannten Formatelementen, vermischt sind, die einem Objekt in der Parameterliste dieser Methode entsprechen. Der Formatierungsprozess ersetzt jedes Formatelement durch die Textdarstellung des Werts des entsprechenden Objekts.
Die Syntax eines Formatelements ist {
index[,
alignment][:
formatString]}
, der einen obligatorischen Index, die optionale Länge und Ausrichtung des formatierten Texts sowie eine optionale Zeichenfolge von Formatbezeichnerzeichen angibt, die bestimmen, wie der Wert des entsprechenden Objekts formatiert wird.
.NET bietet umfangreiche Formatierungsunterstützung, die in den folgenden Formatierungsthemen ausführlicher beschrieben wird.
Weitere Informationen zur zusammengesetzten Formatierungsfunktion, die von Methoden wie Format, AppendFormatund einigen Überladungen von WriteLineunterstützt wird, finden Sie unter Zusammengesetzte Formatierung.
Weitere Informationen zu numerischen Formatbezeichnern finden Sie unter Numerische Standardformatzeichenfolgen und benutzerdefinierte numerische Formatzeichenfolgen.
Weitere Informationen zu Datums- und Uhrzeitformatbezeichnern finden Sie unter Standard-Datums- und Uhrzeitformatzeichenfolgen und benutzerdefinierte Datums- und Uhrzeitformatzeichenfolgen.
Weitere Informationen zu Enumerationsformatbezeichnern finden Sie unter Enumerationsformatzeichenfolgen.
Weitere Informationen zur Formatierung finden Sie unter Formatierungstypen.
Der arg
Parameter ist ein Parameterarray. Argumente können entweder als Array oder als Liste von fünf oder mehr Elementen an die -Methode übergeben werden. Die Beispiele veranschaulichen beide Methodenaufrufe.
Hinweise für Aufrufer
Diese Methode wird nicht durch C++-Code aufgerufen. Der C++-Compiler löst Aufrufe von System.Console.Write auf, die eine Zeichenfolge und eine Liste von vier oder mehr Objektparametern als Aufruf von Write(String, Object, Object, Object, Object)enthalten. Es löst Aufrufe von System.Console.Write auf, die eine Zeichenfolge und ein Objektarray als Aufruf von Write(String, Object)enthalten.
Weitere Informationen
Gilt für:
Write(String, Object)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung des angegebenen Objekts unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream.
public:
static void Write(System::String ^ format, System::Object ^ arg0);
public static void Write (string format, object? arg0);
public static void Write (string format, object arg0);
static member Write : string * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object)
Parameter
- format
- String
Eine kombinierte Formatzeichenfolge.
- arg0
- Object
Ein mit format
zu schreibendes Objekt.
Ausnahmen
E/A-Fehler
format
ist null
.
Die Formatangabe in format
ist ungültig.
Beispiele
Im folgenden Beispiel werden die Standardformatbezeichner für Zahlen, Datumsangaben und Enumerationen mithilfe der WriteLine
-Methode veranschaulicht.
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using namespace System;
public enum class Color {Yellow = 1, Blue, Green};
int main()
{
DateTime thisDate = DateTime::Now;
Console::Clear();
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f);
// Format the current date in various ways.
Console::WriteLine("Standard DateTime Format Specifiers");
Console::WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console::WriteLine("Standard Enumeration Format Specifiers");
Console::WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color::Green);
};
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
Console.Clear();
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
open System
type Color =
| Yellow = 1
| Blue = 2
| Green = 3
let thisDate = DateTime.Now
Console.Clear()
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f)
// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate)
// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green)
// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
// (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
// (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
// (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'
Im folgenden Beispiel wird die Verwendung der Write-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Diese Methode verwendet das zusammengesetzte Formatierungsfeature von .NET, um den Wert eines Objekts in seine Textdarstellung zu konvertieren und diese Darstellung in eine Zeichenfolge einzubetten. Die resultierende Zeichenfolge wird in den Ausgabedatenstrom geschrieben.
Der format
Parameter besteht aus null oder mehr Textausführungen, die mit null oder mehr indizierten Platzhaltern, sogenannten Formatelementen, vermischt sind, die einem Objekt in der Parameterliste dieser Methode entsprechen. Der Formatierungsprozess ersetzt jedes Formatelement durch die Textdarstellung des Werts des entsprechenden Objekts.
Die Syntax eines Formatelements ist {
index[,
alignment][:
formatString]}
, der einen obligatorischen Index, die optionale Länge und Ausrichtung des formatierten Texts sowie eine optionale Zeichenfolge von Formatbezeichnerzeichen angibt, die bestimmen, wie der Wert des entsprechenden Objekts formatiert wird.
.NET bietet umfangreiche Formatierungsunterstützung, die in den folgenden Formatierungsthemen ausführlicher beschrieben wird.
Weitere Informationen zur zusammengesetzten Formatierungsfunktion, die von Methoden wie Format, AppendFormatund einigen Überladungen von WriteLineunterstützt wird, finden Sie unter Zusammengesetzte Formatierung.
Weitere Informationen zu numerischen Formatbezeichnern finden Sie unter Numerische Standardformatzeichenfolgen und benutzerdefinierte numerische Formatzeichenfolgen.
Weitere Informationen zu Datums- und Uhrzeitformatbezeichnern finden Sie unter Standard-Datums- und Uhrzeitformatzeichenfolgen und benutzerdefinierte Datums- und Uhrzeitformatzeichenfolgen.
Weitere Informationen zu Enumerationsformatbezeichnern finden Sie unter Enumerationsformatzeichenfolgen.
Weitere Informationen zur Formatierung finden Sie unter Formatierungstypen.
Weitere Informationen
Gilt für:
Write(UInt64)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Wichtig
Diese API ist nicht CLS-kompatibel.
Schreibt die Textdarstellung der angegebenen 64-Bit-Ganzzahl ohne Vorzeichen in den Standardausgabestream.
public:
static void Write(System::UInt64 value);
[System.CLSCompliant(false)]
public static void Write (ulong value);
[<System.CLSCompliant(false)>]
static member Write : uint64 -> unit
Public Shared Sub Write (value As ULong)
Parameter
- value
- UInt64
Der zu schreibende Wert.
- Attribute
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von value
wird durch Aufrufen der UInt64.ToString -Methode erzeugt.
Weitere Informationen
Gilt für:
Write(UInt32)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Wichtig
Diese API ist nicht CLS-kompatibel.
Schreibt die Textdarstellung der angegebenen 32-Bit-Ganzzahl ohne Vorzeichen in den Standardausgabestream.
public:
static void Write(System::UInt32 value);
[System.CLSCompliant(false)]
public static void Write (uint value);
[<System.CLSCompliant(false)>]
static member Write : uint32 -> unit
Public Shared Sub Write (value As UInteger)
Parameter
- value
- UInt32
Der zu schreibende Wert.
- Attribute
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von value
wird durch Aufrufen der UInt32.ToString -Methode erzeugt.
Weitere Informationen
Gilt für:
Write(String)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die angegebene Zeichenfolge in den Standardausgabestream.
public:
static void Write(System::String ^ value);
public static void Write (string? value);
public static void Write (string value);
static member Write : string -> unit
Public Shared Sub Write (value As String)
Parameter
- value
- String
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Wenn der Wert ist null
, wird nichts in den Standardausgabedatenstrom geschrieben.
Weitere Informationen
Gilt für:
Write(String, Object, Object)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung der angegebenen Objekte unter Verwendung der angegebenen Formatinformationen in den Standardausgabestream.
public:
static void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public static void Write (string format, object? arg0, object? arg1);
public static void Write (string format, object arg0, object arg1);
static member Write : string * obj * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object, arg1 As Object)
Parameter
- format
- String
Eine kombinierte Formatzeichenfolge.
- arg0
- Object
Das erste mit format
zu schreibende Objekt.
- arg1
- Object
Das zweite mit format
zu schreibende Objekt.
Ausnahmen
E/A-Fehler
format
ist null
.
Die Formatangabe in format
ist ungültig.
Beispiele
Im folgenden Beispiel werden die Standardformatbezeichner für Zahlen, Datumsangaben und Enumerationen mithilfe der WriteLine
-Methode veranschaulicht.
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using namespace System;
public enum class Color {Yellow = 1, Blue, Green};
int main()
{
DateTime thisDate = DateTime::Now;
Console::Clear();
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f);
// Format the current date in various ways.
Console::WriteLine("Standard DateTime Format Specifiers");
Console::WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console::WriteLine("Standard Enumeration Format Specifiers");
Console::WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color::Green);
};
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
Console.Clear();
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
open System
type Color =
| Yellow = 1
| Blue = 2
| Green = 3
let thisDate = DateTime.Now
Console.Clear()
// Format a negative integer or floating-point number in various ways.
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",
-123, -123.45f)
// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate)
// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green)
// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
// (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
// (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
// (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Diese Methode verwendet die zusammengesetzte Formatierungsfunktion von .NET, um den Wert eines Objekts in seine Textdarstellung zu konvertieren und diese Darstellung in eine Zeichenfolge einzubetten. Die resultierende Zeichenfolge wird in den Ausgabedatenstrom geschrieben.
Der format
Parameter besteht aus null oder mehr Textausführungen, die mit null oder mehr indizierten Platzhaltern, sogenannten Formatelementen, vermischt sind, die einem Objekt in der Parameterliste dieser Methode entsprechen. Der Formatierungsprozess ersetzt jedes Formatelement durch die Textdarstellung des Werts des entsprechenden Objekts.
Die Syntax eines Formatelements ist {
index[,
alignment][:
formatString]}
, der einen obligatorischen Index, die optionale Länge und Ausrichtung des formatierten Texts sowie eine optionale Zeichenfolge von Formatbezeichnerzeichen angibt, die bestimmen, wie der Wert des entsprechenden Objekts formatiert wird.
.NET bietet umfangreiche Formatierungsunterstützung, die in den folgenden Formatierungsthemen ausführlicher beschrieben wird.
Weitere Informationen zur zusammengesetzten Formatierungsfunktion, die von Methoden wie Format, AppendFormatund einigen Überladungen von WriteLineunterstützt wird, finden Sie unter Zusammengesetzte Formatierung.
Weitere Informationen zu numerischen Formatbezeichnern finden Sie unter Numerische Standardformatzeichenfolgen und benutzerdefinierte numerische Formatzeichenfolgen.
Weitere Informationen zu Datums- und Uhrzeitformatbezeichnern finden Sie unter Standard-Datums- und Uhrzeitformatzeichenfolgen und benutzerdefinierte Datums- und Uhrzeitformatzeichenfolgen.
Weitere Informationen zu Enumerationsformatbezeichnern finden Sie unter Enumerationsformatzeichenfolgen.
Weitere Informationen zur Formatierung finden Sie unter Formatierungstypen.
Weitere Informationen
Gilt für:
Write(Object)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung des angegebenen Objekts in den Standardausgabestream.
public:
static void Write(System::Object ^ value);
public static void Write (object? value);
public static void Write (object value);
static member Write : obj -> unit
Public Shared Sub Write (value As Object)
Parameter
- value
- Object
Der zu schreibende Wert oder null
.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Wenn value
ist null
, wird nichts geschrieben, und es wird keine Ausnahme ausgelöst. Andernfalls wird die ToString
Methode von value
aufgerufen, um ihre Zeichenfolgendarstellung zu erzeugen, und die resultierende Zeichenfolge wird in den Standardausgabedatenstrom geschrieben.
Weitere Informationen
Gilt für:
Write(Single)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung der angegebenen Gleitkommazahl mit einfacher Genauigkeit in den Standardausgabestream.
public:
static void Write(float value);
public static void Write (float value);
static member Write : single -> unit
Public Shared Sub Write (value As Single)
Parameter
- value
- Single
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von value
wird durch Aufrufen der Single.ToString -Methode erzeugt.
Weitere Informationen
Gilt für:
Write(Char)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt das angegebene Unicode-Zeichen in den Standardausgabestream.
public:
static void Write(char value);
public static void Write (char value);
static member Write : char -> unit
Public Shared Sub Write (value As Char)
Parameter
- value
- Char
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Weitere Informationen
Gilt für:
Write(Char[])
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt das angegebene Array von Unicode-Zeichen in den Standardausgabestream.
public:
static void Write(cli::array <char> ^ buffer);
public static void Write (char[]? buffer);
public static void Write (char[] buffer);
static member Write : char[] -> unit
Public Shared Sub Write (buffer As Char())
Parameter
- buffer
- Char[]
Ein Array von Unicode-Zeichen.
Ausnahmen
E/A-Fehler
Weitere Informationen
Gilt für:
Write(Boolean)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung des angegebenen booleschen Werts in den Standardausgabestream.
public:
static void Write(bool value);
public static void Write (bool value);
static member Write : bool -> unit
Public Shared Sub Write (value As Boolean)
Parameter
- value
- Boolean
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von wird durch Aufrufen Boolean.ToStringvon value
erzeugt, wodurch entweder Boolean.TrueString oder Boolean.FalseStringausgegeben wird.
Weitere Informationen
Gilt für:
Write(Double)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung der angegebenen Gleitkommazahl mit doppelter Genauigkeit in den Standardausgabestream.
public:
static void Write(double value);
public static void Write (double value);
static member Write : double -> unit
Public Shared Sub Write (value As Double)
Parameter
- value
- Double
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von value
wird durch Aufrufen der Double.ToString -Methode erzeugt.
Weitere Informationen
Gilt für:
Write(Int32)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung der angegebenen 32-Bit-Ganzzahl mit Vorzeichen in den Standardausgabestream.
public:
static void Write(int value);
public static void Write (int value);
static member Write : int -> unit
Public Shared Sub Write (value As Integer)
Parameter
- value
- Int32
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von value
wird durch Aufrufen der Int32.ToString -Methode erzeugt.
Weitere Informationen
Gilt für:
Write(Int64)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung der angegebenen 64-Bit-Ganzzahl mit Vorzeichen in den Standardausgabestream.
public:
static void Write(long value);
public static void Write (long value);
static member Write : int64 -> unit
Public Shared Sub Write (value As Long)
Parameter
- value
- Int64
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von value
wird durch Aufrufen der Int64.ToString -Methode erzeugt.
Weitere Informationen
Gilt für:
Write(Decimal)
- Quelle:
- Console.cs
- Quelle:
- Console.cs
- Quelle:
- Console.cs
Schreibt die Textdarstellung des angegebenen Decimal-Werts in den Standardausgabestream.
public:
static void Write(System::Decimal value);
public static void Write (decimal value);
static member Write : decimal -> unit
Public Shared Sub Write (value As Decimal)
Parameter
- value
- Decimal
Der zu schreibende Wert.
Ausnahmen
E/A-Fehler
Beispiele
Im folgenden Beispiel wird die Verwendung der Write
-Methode veranschaulicht.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
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 (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Hinweise
Die Textdarstellung von wird durch Aufrufen Decimal.ToStringvon value
erzeugt.
Weitere Informationen
Gilt für:
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für