c语言中console.WriteLine指的是什么

来源:这里教程网 时间:2026-02-21 16:46:23 作者:

C# 中的 Console.WriteLine

什么是 Console.WriteLine?

Console.WriteLine 是 C# 中的一个方法,用于在控制台窗口中输出指定的信息。它属于 System.Console 名称空间。

功能与用途

立即学习“C语言免费学习笔记(深入)”;

Console.WriteLine 将对象的值转换为字符串形式并将其输出到当前控制台窗口的末尾。 它可以输出各种类型的值,包括字符串、数字、布尔值和自定义类型。 Console.WriteLine 可以使用重载版本,允许指定要打印的其他信息,例如换行符或格式字符串。

语法

<code class="csharp">public static void WriteLine(object value);
public static void WriteLine();
public static void WriteLine(string format, params object[] args);</code>

使用示例

<code class="csharp">Console.WriteLine("Hello World!");
Console.WriteLine(123);
Console.WriteLine(true);</code>

输出:

<code>Hello World!
123
True</code>

其他信息

Console.WriteLine 总是输出一行文本,并在末尾添加一个换行符。 使用 Console.Write 方法可以输出文本而不会添加换行符。 对于复杂输出场景,可以考虑使用 String.Format 方法来格式化输出。

相关推荐