Console.Write Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Zapisuje tekstową reprezentację określonej wartości lub wartości w standardowym strumieniu wyjściowym.
Przeciążenia
Write(String, Object, Object, Object, Object) |
Zapisuje tekstową reprezentację określonych obiektów i listy parametrów o zmiennej długości do standardowego strumienia wyjściowego przy użyciu określonych informacji o formacie. |
Write(String, Object, Object, Object) |
Zapisuje reprezentację tekstową określonych obiektów w standardowym strumieniu wyjściowym przy użyciu określonych informacji o formacie. |
Write(Char[], Int32, Int32) |
Zapisuje określoną podtablicę znaków Unicode do standardowego strumienia wyjściowego. |
Write(String, ReadOnlySpan<Object>) | |
Write(String, Object[]) |
Zapisuje reprezentację tekstową określonej tablicy obiektów do standardowego strumienia wyjściowego przy użyciu określonych informacji o formacie. |
Write(String, Object) |
Zapisuje reprezentację tekstową określonego obiektu w standardowym strumieniu wyjściowym przy użyciu określonych informacji o formacie. |
Write(UInt64) |
Zapisuje reprezentację tekstową określonej 64-bitowej wartości całkowitej bez znaku do standardowego strumienia wyjściowego. |
Write(UInt32) |
Zapisuje reprezentację tekstową określonej 32-bitowej niepodpisanej wartości całkowitej do standardowego strumienia wyjściowego. |
Write(String) |
Zapisuje określoną wartość ciągu do standardowego strumienia wyjściowego. |
Write(String, Object, Object) |
Zapisuje reprezentację tekstową określonych obiektów w standardowym strumieniu wyjściowym przy użyciu określonych informacji o formacie. |
Write(Object) |
Zapisuje reprezentację tekstową określonego obiektu w standardowym strumieniu wyjściowym. |
Write(Single) |
Zapisuje reprezentację tekstową określonej wartości zmiennoprzecinkowej o pojedynczej precyzji do standardowego strumienia wyjściowego. |
Write(Char) |
Zapisuje określoną wartość znaku Unicode do standardowego strumienia wyjściowego. |
Write(Char[]) |
Zapisuje określoną tablicę znaków Unicode do standardowego strumienia wyjściowego. |
Write(Boolean) |
Zapisuje reprezentację tekstową określonej wartości logicznej w standardowym strumieniu wyjściowym. |
Write(Double) |
Zapisuje reprezentację tekstową określonej wartości zmiennoprzecinkowej o podwójnej precyzji do standardowego strumienia wyjściowego. |
Write(Int32) |
Zapisuje reprezentację tekstową określonej 32-bitowej liczby całkowitej ze znakiem do standardowego strumienia wyjściowego. |
Write(Int64) |
Zapisuje reprezentację tekstową określonej 64-bitowej liczby całkowitej ze znakiem do standardowego strumienia wyjściowego. |
Write(Decimal) |
Zapisuje tekstową reprezentację określonej Decimal wartości w standardowym strumieniu wyjściowym. |
Write(String, Object, Object, Object, Object)
Ważne
Ten interfejs API nie jest zgodny ze specyfikacją CLS.
Zapisuje tekstową reprezentację określonych obiektów i listy parametrów o zmiennej długości do standardowego strumienia wyjściowego przy użyciu określonych informacji o formacie.
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)
Parametry
- format
- String
Ciąg formatu złożonego.
- arg0
- Object
Pierwszy obiekt do zapisania przy użyciu polecenia format
.
- arg1
- Object
Drugi obiekt do zapisania przy użyciu polecenia format
.
- arg2
- Object
Trzeci obiekt do zapisania przy użyciu polecenia format
.
- arg3
- Object
Czwarty obiekt do zapisania przy użyciu polecenia format
.
- Atrybuty
Wyjątki
Wystąpił błąd we/wy.
format
to null
.
Specyfikacja formatu w pliku format
jest nieprawidłowa.
Przykłady
Poniższy przykład ilustruje użycie parametrów zmiennych z Write(String, Object, Object, Object, Object) metodą . Metoda jest wywoływana z ciągiem formatu złożonego i pięcioma elementami formatu.
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
Uwagi
Uwaga
Ten interfejs API nie jest zgodny ze specyfikacją CLS. Alternatywą zgodną ze specyfikacją CLS jest Console.Write(String, Object[]). Kompilatory języka C# i Visual Basic automatycznie rozpoznają wywołanie tej metody jako wywołanie metody Console.Write(String, Object[]).
Ta metoda używa funkcji formatowania złożonego platformy .NET, aby przekonwertować wartość obiektu na jego reprezentację tekstową i osadzić tę reprezentację w ciągu. Wynikowy ciąg jest zapisywany do strumienia wyjściowego.
Parametr format
składa się z zera lub większej liczby przebiegów tekstu zmieszanego z zero lub większą większa liczba indeksowanych symboli zastępczych, nazywanych elementami formatu, które odpowiadają obiektowi na liście parametrów tej metody. Proces formatowania zastępuje każdy element formatu tekstową reprezentacja wartości odpowiedniego obiektu.
Składnia elementu formatu to {
index[,
alignment][:
formatString]}
, który określa obowiązkowy indeks, opcjonalną długość i wyrównanie sformatowanego tekstu oraz opcjonalny ciąg znaków specyfikatora formatu, które określają sposób formatowania wartości odpowiedniego obiektu.
Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w poniższych tematach formatowania.
Aby uzyskać więcej informacji na temat funkcji formatowania złożonego obsługiwanej przez metody, takie jak Format, AppendFormati niektóre przeciążenia WriteLineprogramu , zobacz Formatowanie złożone.
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat specyfikatorów formatu daty i godziny, zobacz Standardowe ciągi formatu daty i godziny oraz Niestandardowe ciągi formatu daty i godziny.
Aby uzyskać więcej informacji na temat specyfikatorów formatu wyliczenia, zobacz Ciągi formatu wyliczenia.
Aby uzyskać więcej informacji na temat formatowania, zobacz Typy formatowania.
Uwagi dotyczące wywoływania
Ta metoda jest oznaczona vararg
słowem kluczowym, co oznacza, że obsługuje zmienną liczbę parametrów. Metodę można wywołać z języka Visual C++, ale nie można jej wywołać z poziomu kodu C# lub Visual Basic. Kompilatory języka C# i Visual Basic rozwiązują wywołania jako Write(String, Object, Object, Object, Object) wywołania .Write(String, Object[])
Zobacz też
Dotyczy
Write(String, Object, Object, Object)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonych obiektów w standardowym strumieniu wyjściowym przy użyciu określonych informacji o formacie.
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)
Parametry
- format
- String
Ciąg formatu złożonego.
- arg0
- Object
Pierwszy obiekt do zapisania przy użyciu polecenia format
.
- arg1
- Object
Drugi obiekt do zapisania przy użyciu polecenia format
.
- arg2
- Object
Trzeci obiekt do zapisania przy użyciu polecenia format
.
Wyjątki
Wystąpił błąd we/wy.
format
to null
.
Specyfikacja formatu w pliku format
jest nieprawidłowa.
Przykłady
W poniższym przykładzie użyto WriteLine
metody , aby zademonstrować standardowe specyfikatory formatowania liczb, dat i wyliczenia.
// 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
'
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Ta metoda używa funkcji formatowania złożonego platformy .NET, aby przekonwertować wartość obiektu na jego reprezentację tekstową i osadzić tę reprezentację w ciągu. Wynikowy ciąg jest zapisywany do strumienia wyjściowego.
Parametr format
składa się z zera lub większej liczby przebiegów tekstu zmieszanego z zero lub większą większa liczba indeksowanych symboli zastępczych, nazywanych elementami formatu, które odpowiadają obiektowi na liście parametrów tej metody. Proces formatowania zastępuje każdy element formatu tekstową reprezentacja wartości odpowiedniego obiektu.
Składnia elementu formatu to {
index[,
alignment][:
formatString]}
, który określa obowiązkowy indeks, opcjonalną długość i wyrównanie sformatowanego tekstu oraz opcjonalny ciąg znaków specyfikatora formatu, które określają sposób formatowania wartości odpowiedniego obiektu.
Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w poniższych tematach formatowania.
Aby uzyskać więcej informacji na temat funkcji formatowania złożonego obsługiwanej przez metody, takie jak Format, AppendFormati niektóre przeciążenia WriteLineprogramu , zobacz Formatowanie złożone.
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat specyfikatorów formatu daty i godziny, zobacz Standardowe ciągi formatu daty i godziny oraz Niestandardowe ciągi formatu daty i godziny.
Aby uzyskać więcej informacji na temat specyfikatorów formatu wyliczenia, zobacz Ciągi formatu wyliczenia.
Aby uzyskać więcej informacji na temat formatowania, zobacz Typy formatowania.
Zobacz też
Dotyczy
Write(Char[], Int32, Int32)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje określony podarraj znaków Unicode do standardowego strumienia wyjściowego.
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)
Parametry
- buffer
- Char[]
Tablica znaków Unicode.
- index
- Int32
Pozycja początkowa w elemecie buffer
.
- count
- Int32
Liczba znaków, jaka ma zostać zapisana.
Wyjątki
buffer
to null
.
index
wartość lub count
jest mniejsza niż zero.
index
plus count
określ pozycję, która nie znajduje się w obiekcie buffer
.
Wystąpił błąd we/wy.
Uwagi
Ta metoda zapisuje znaki rozpoczynające count
się od pozycji buffer
index
standardowego strumienia wyjściowego.
Zobacz też
Dotyczy
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))
Parametry
- format
- String
- arg
- ReadOnlySpan<Object>
Dotyczy
Write(String, Object[])
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonej tablicy obiektów do standardowego strumienia wyjściowego przy użyciu określonych informacji o formacie.
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())
Parametry
- format
- String
Ciąg formatu złożonego.
- arg
- Object[]
Tablica obiektów do zapisu przy użyciu polecenia format
.
Wyjątki
Wystąpił błąd we/wy.
format
lub arg
to null
.
Specyfikacja formatu w pliku format
jest nieprawidłowa.
Przykłady
W poniższym przykładzie zdefiniowano klasę Person
z wieloma właściwościami, które zawierają informacje o osobie. Metoda GetDescription
zwraca tablicę zawierającą wszystkie wartości właściwości z wyjątkiem jednej. W tym przykładzie GetDescription
użyto tablicy zwróconej przez metodę, aby wyświetlić wartości obiektu Person.
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
Należy pamiętać, że przykład wywołuje metodę Write(String, Object[]) , a nie WriteLine(String, Object[]) metodę, ponieważ próbuje wyświetlić wartość Person.Remarks
właściwości w tym samym wierszu. Aby to zrobić, sprawdza wartość CursorLeft właściwości i WindowWidth , aby określić, czy jest wystarczająca ilość miejsca, aby uwagi pasowały. Jeśli tak jest, wyświetla wiersz. Jeśli tak nie jest, zapisuje wiersz, wcięcie trzech spacji i wyświetla uwagę.
Poniższy przykład jest identyczny z pierwszym, z wyjątkiem tego, że dostarcza listę pięciu elementów jako arg
argument zamiast tablicy parametrów.
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
Uwagi
Ta metoda używa funkcji formatowania złożonego platformy .NET, aby przekonwertować wartość obiektu na jej reprezentację tekstową i osadzić tę reprezentację w ciągu. Wynikowy ciąg jest zapisywany do strumienia wyjściowego.
Parametr format
składa się z zera lub większej liczby przebiegów tekstu w połączeniu z zero lub większą częścią indeksowanych symboli zastępczych, nazywanych elementami formatu, które odpowiadają obiektowi na liście parametrów tej metody. Proces formatowania zastępuje każdy element formatu tekstową reprezentacja wartości odpowiedniego obiektu.
Składnia elementu formatu to {
index[,
alignment][:
formatString]}
, który określa obowiązkowy indeks, opcjonalną długość i wyrównanie sformatowanego tekstu oraz opcjonalny ciąg znaków specyfikatora formatu, które określają sposób formatowania wartości odpowiedniego obiektu.
Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została opisana bardziej szczegółowo w poniższych tematach formatowania.
Aby uzyskać więcej informacji na temat funkcji formatowania złożonego obsługiwanej przez metody, takie jak Format, AppendFormati niektóre przeciążenia WriteLineprogramu , zobacz Formatowanie złożone.
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat specyfikatorów formatu daty i godziny, zobacz Standardowe ciągi formatu daty i godziny oraz niestandardowe ciągi formatudaty i godziny.
Aby uzyskać więcej informacji na temat specyfikatorów formatu wyliczenia, zobacz Ciągi formatu wyliczenia.
Aby uzyskać więcej informacji na temat formatowania, zobacz Typy formatowania.
Parametr arg
jest tablicą parametrów. Argumenty można przekazać do metody jako tablicę lub jako listę pięciu lub więcej elementów. Przykłady ilustrują obie formy wywołania metody.
Uwagi dotyczące wywoływania
Ta metoda nie jest wywoływana przez kod C++. Kompilator języka C++ rozpoznaje wywołania elementu System.Console.Write , które zawierają ciąg i listę czterech lub większej liczby parametrów obiektu jako wywołanie metody Write(String, Object, Object, Object, Object). Rozwiązuje to wywołania elementu System.Console.Write , które zawierają ciąg i tablicę obiektów jako wywołanie metody Write(String, Object).
Zobacz też
Dotyczy
Write(String, Object)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonego obiektu w standardowym strumieniu wyjściowym przy użyciu określonych informacji o formacie.
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)
Parametry
- format
- String
Ciąg formatu złożonego.
- arg0
- Object
Obiekt do zapisu przy użyciu polecenia format
.
Wyjątki
Wystąpił błąd we/wy.
format
to null
.
Specyfikacja formatu w pliku format
jest nieprawidłowa.
Przykłady
W poniższym przykładzie WriteLine
użyto metody do zademonstrowania standardowych specyfikatorów formatowania liczb, dat i wyliczenia.
// 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
'
Poniższy przykład ilustruje użycie Write metody .
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
Uwagi
Ta metoda używa funkcji formatowania złożonego platformy .NET, aby przekonwertować wartość obiektu na jej reprezentację tekstową i osadzić tę reprezentację w ciągu. Wynikowy ciąg jest zapisywany do strumienia wyjściowego.
Parametr format
składa się z zera lub większej liczby przebiegów tekstu w połączeniu z zero lub większą częścią indeksowanych symboli zastępczych, nazywanych elementami formatu, które odpowiadają obiektowi na liście parametrów tej metody. Proces formatowania zastępuje każdy element formatu tekstową reprezentacja wartości odpowiedniego obiektu.
Składnia elementu formatu to {
index[,
alignment][:
formatString]}
, który określa obowiązkowy indeks, opcjonalną długość i wyrównanie sformatowanego tekstu oraz opcjonalny ciąg znaków specyfikatora formatu, które określają sposób formatowania wartości odpowiedniego obiektu.
Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została opisana bardziej szczegółowo w poniższych tematach formatowania.
Aby uzyskać więcej informacji na temat funkcji formatowania złożonego obsługiwanej przez metody, takie jak Format, AppendFormati niektóre przeciążenia WriteLineprogramu , zobacz Formatowanie złożone.
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat specyfikatorów formatu daty i godziny, zobacz Standardowe ciągi formatu daty i godziny oraz niestandardowe ciągi formatudaty i godziny.
Aby uzyskać więcej informacji na temat specyfikatorów formatu wyliczenia, zobacz Ciągi formatu wyliczenia.
Aby uzyskać więcej informacji na temat formatowania, zobacz Typy formatowania.
Zobacz też
Dotyczy
Write(UInt64)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Ważne
Ten interfejs API nie jest zgodny ze specyfikacją CLS.
Zapisuje reprezentację tekstową określonej 64-bitowej wartości całkowitej bez znaku do standardowego strumienia wyjściowego.
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)
Parametry
- value
- UInt64
Wartość do zapisu.
- Atrybuty
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Reprezentacja tekstowa value
elementu jest generowany przez wywołanie UInt64.ToString metody .
Zobacz też
Dotyczy
Write(UInt32)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Ważne
Ten interfejs API nie jest zgodny ze specyfikacją CLS.
Zapisuje reprezentację tekstową określonej 32-bitowej wartości całkowitej bez znaku do standardowego strumienia wyjściowego.
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)
Parametry
- value
- UInt32
Wartość do zapisu.
- Atrybuty
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Reprezentacja tekstowa value
elementu jest generowany przez wywołanie UInt32.ToString metody .
Zobacz też
Dotyczy
Write(String)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje określoną wartość ciągu w standardowym strumieniu wyjściowym.
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)
Parametry
- value
- String
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Jeśli wartość to null
, nic nie jest zapisywane w standardowym strumieniu wyjściowym.
Zobacz też
Dotyczy
Write(String, Object, Object)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonych obiektów w standardowym strumieniu wyjściowym przy użyciu określonych informacji o formacie.
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)
Parametry
- format
- String
Ciąg formatu złożonego.
- arg0
- Object
Pierwszy obiekt do zapisu przy użyciu polecenia format
.
- arg1
- Object
Drugi obiekt do zapisu przy użyciu polecenia format
.
Wyjątki
Wystąpił błąd we/wy.
format
to null
.
Specyfikacja formatu w pliku format
jest nieprawidłowa.
Przykłady
W poniższym przykładzie WriteLine
użyto metody do zademonstrowania standardowych specyfikatorów formatowania liczb, dat i wyliczenia.
// 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
'
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Ta metoda używa funkcji formatowania złożonego platformy .NET, aby przekonwertować wartość obiektu na jej reprezentację tekstową i osadzić tę reprezentację w ciągu. Wynikowy ciąg jest zapisywany do strumienia wyjściowego.
Parametr format
składa się z zera lub większej liczby przebiegów tekstu w połączeniu z zero lub większą częścią indeksowanych symboli zastępczych, nazywanych elementami formatu, które odpowiadają obiektowi na liście parametrów tej metody. Proces formatowania zastępuje każdy element formatu tekstową reprezentacja wartości odpowiedniego obiektu.
Składnia elementu formatu to {
index[,
alignment][:
formatString]}
, który określa obowiązkowy indeks, opcjonalną długość i wyrównanie sformatowanego tekstu oraz opcjonalny ciąg znaków specyfikatora formatu, które określają sposób formatowania wartości odpowiedniego obiektu.
Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została opisana bardziej szczegółowo w poniższych tematach formatowania.
Aby uzyskać więcej informacji na temat funkcji formatowania złożonego obsługiwanej przez metody, takie jak Format, AppendFormati niektóre przeciążenia WriteLineprogramu , zobacz Formatowanie złożone.
Aby uzyskać więcej informacji na temat specyfikatorów formatu liczbowego, zobacz Standardowe ciągi formatu liczbowego i Niestandardowe ciągi formatu liczbowego.
Aby uzyskać więcej informacji na temat specyfikatorów formatu daty i godziny, zobacz Standardowe ciągi formatu daty i godziny oraz niestandardowe ciągi formatudaty i godziny.
Aby uzyskać więcej informacji na temat specyfikatorów formatu wyliczenia, zobacz Ciągi formatu wyliczenia.
Aby uzyskać więcej informacji na temat formatowania, zobacz Typy formatowania.
Zobacz też
Dotyczy
Write(Object)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonego obiektu w standardowym strumieniu wyjściowym.
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)
Parametry
- value
- Object
Wartość do zapisu lub null
.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Jeśli value
jest to null
, nic nie jest napisane i nie jest zgłaszany żaden wyjątek. ToString
W przeciwnym razie metoda value
jest wywoływana w celu wygenerowania reprezentacji ciągu, a wynikowy ciąg jest zapisywany w standardowym strumieniu wyjściowym.
Zobacz też
Dotyczy
Write(Single)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonej wartości zmiennoprzecinkowej o pojedynczej precyzji do standardowego strumienia wyjściowego.
public:
static void Write(float value);
public static void Write (float value);
static member Write : single -> unit
Public Shared Sub Write (value As Single)
Parametry
- value
- Single
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Tekstowa reprezentacja value
elementu jest generowany przez wywołanie Single.ToString metody .
Zobacz też
Dotyczy
Write(Char)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje określoną wartość znaku Unicode do standardowego strumienia wyjściowego.
public:
static void Write(char value);
public static void Write (char value);
static member Write : char -> unit
Public Shared Sub Write (value As Char)
Parametry
- value
- Char
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Zobacz też
Dotyczy
Write(Char[])
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje określoną tablicę znaków Unicode do standardowego strumienia wyjściowego.
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())
Parametry
- buffer
- Char[]
Tablica znaków Unicode.
Wyjątki
Wystąpił błąd we/wy.
Zobacz też
Dotyczy
Write(Boolean)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonej wartości logicznej w standardowym strumieniu wyjściowym.
public:
static void Write(bool value);
public static void Write (bool value);
static member Write : bool -> unit
Public Shared Sub Write (value As Boolean)
Parametry
- value
- Boolean
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Tekstowa reprezentacja value
elementu jest generowany przez wywołanie Boolean.ToStringmetody , która zwraca dane wyjściowe Boolean.TrueString lub Boolean.FalseString.
Zobacz też
Dotyczy
Write(Double)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonej wartości zmiennoprzecinkowej o podwójnej precyzji do standardowego strumienia wyjściowego.
public:
static void Write(double value);
public static void Write (double value);
static member Write : double -> unit
Public Shared Sub Write (value As Double)
Parametry
- value
- Double
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Tekstowa reprezentacja value
elementu jest generowany przez wywołanie Double.ToString metody .
Zobacz też
Dotyczy
Write(Int32)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonej 32-bitowej liczby całkowitej ze znakiem do standardowego strumienia wyjściowego.
public:
static void Write(int value);
public static void Write (int value);
static member Write : int -> unit
Public Shared Sub Write (value As Integer)
Parametry
- value
- Int32
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Tekstowa reprezentacja value
elementu jest generowany przez wywołanie Int32.ToString metody .
Zobacz też
Dotyczy
Write(Int64)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje reprezentację tekstową określonej 64-bitowej liczby całkowitej ze znakiem do standardowego strumienia wyjściowego.
public:
static void Write(long value);
public static void Write (long value);
static member Write : int64 -> unit
Public Shared Sub Write (value As Long)
Parametry
- value
- Int64
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Tekstowa reprezentacja value
elementu jest generowany przez wywołanie Int64.ToString metody .
Zobacz też
Dotyczy
Write(Decimal)
- Źródło:
- Console.cs
- Źródło:
- Console.cs
- Źródło:
- Console.cs
Zapisuje tekstową reprezentację określonej Decimal wartości w standardowym strumieniu wyjściowym.
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)
Parametry
- value
- Decimal
Wartość do zapisu.
Wyjątki
Wystąpił błąd we/wy.
Przykłady
Poniższy przykład ilustruje użycie Write
metody .
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
Uwagi
Tekstowa reprezentacja value
elementu jest generowany przez wywołanie metody Decimal.ToString.
Zobacz też
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla