指定した書式情報を使用して、指定したオブジェクトと可変長パラメータ リストを標準出力ストリームに書き込みます。
このメソッドは、CLS と互換性がありません。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
[CLSCompliant(false)]
public: static void Write(String* format,Object* arg0,Object* arg1,Object* arg2,Object* arg3, ...);
[Visual Basic] Visual Basic では、このメソッドを使用することはできません。
[C#] C# では、このメソッドを使用することはできません。
[JScript] JScript では、このメソッドを使用することはできません。
パラメータ [C++]
- format
書式指定文字列。 - arg0
format を使用して書き込む最初のオブジェクト。 - arg1
format を使用して書き込む 2 番目のオブジェクト。 - arg2
format を使用して書き込む 3 番目のオブジェクト。 - arg3
format を使用して書き込む 4 番目のオブジェクト。
例外 [C++]
例外の種類 | 条件 |
---|---|
IOException | I/O エラーが発生しました。 |
ArgumentNullException | format が null 参照 (Visual Basic では Nothing) です。 |
FormatException | format の書式指定が無効です。 |
解説 [C++]
このメソッドは String.Format と同じセマンティクスを使用します。
パラメータ オブジェクトが format で参照されない場合、これは無視されます。
使用例
Write の使用方法については、次のコード例を参照してください。
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String
lineInput = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields() As String = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
Dim item As String
For Each item In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Try
Console.Write(Convert.ToByte(Convert.ToBoolean(item)))
Catch
Console.Write(item)
End Try
Next item
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub 'Main
End Class 'FormatConverter
[C#]
public class FormatConverter {
public static void Main(string[] args) {
string lineInput;
while ((lineInput = Console.ReadLine()) != null) {
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach(string item in fields) {
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
try {
Console.Write(Convert.ToByte(Convert.ToBoolean(item)));
}
catch(FormatException) {
Console.Write(item);
}
}
Console.WriteLine();
}
}
}
[C++]
int main() {
String* lineInputArr __gc[] = {S"1 2.2 hello TRUE", S"2 5.22 bye FALSE", S"3 6.38 see ya' TRUE"};
for( Int32 i = 0; i < 3; i++) {
String* lineInput = lineInputArr->GetValue(i)->ToString();
String* aChar = "\t";
String* fields __gc[] = lineInput->Split(aChar->ToCharArray());
Boolean isFirstField = true;
for (Int32 i = 0; i < fields->Length; i++) {
if (isFirstField)
isFirstField = false;
else
Console::Write(S",");
// If the field represents a boolean, replace with a numeric representation.
try {
Console::Write(Convert::ToByte(Convert::ToBoolean(fields[i])));
}
catch(FormatException*) {
Console::Write(fields[i]);
}
}
Console::WriteLine();
}
}
[JScript]
var lineInput : String;
while ((lineInput = Console.ReadLine()) != null) {
var fields : String[] = lineInput.Split(char[](['\t']));
var isFirstField : Boolean = true;
for(var i in fields) {
var item = fields[i];
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
try {
Console.Write(Convert.ToByte(Convert.ToBoolean(item)));
}
catch(FormatException) {
Console.Write(item);
}
}
Console.WriteLine();
}
必要条件 [C++]
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
Console クラス | Console メンバ | System 名前空間 | Console.Write オーバーロードの一覧 | 書式設定の概要 | Read | ReadLine | WriteLine