System.Console.WriteLine 方法 (String)

方法描述

将指定的字符串值(后跟当前行终止符)写入标准输出流。

语法定义(C# System.Console.WriteLine 方法 (String) 的用法)

[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)]
public static void WriteLine(
	string value
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
value System-String 要写入的值。
返回值 void

提示和注释

如果值为 null,则只将行终止符写入标准输出流。

有关行结束符的更多信息,请参见 WriteLine() 方法的备注部分。

注意

应用到此类型或成员的 HostProtectionAttribute 特性具有以下 Resources 属性值:UI。HostProtectionAttribute 不影响桌面应用程序(桌面应用程序一般通过双击图标、键入命令或在浏览器中输入 URL 启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护特性。

System.Console.WriteLine 方法 (String)例子

然后,它调用 WriteLine() 和 WriteLine(String) 方法来将输出显示到控制台。

using System;

public class Example
{
   public static void Main()
   {
      string[] lines = { "This is the first line.", 
                         "This is the second line." };
      // Output the lines using the default newline sequence.
      Console.WriteLine("With the default new line characters:");
      Console.WriteLine();
      foreach (string line in lines)
         Console.WriteLine(line);

      Console.WriteLine();

      // Redefine the newline characters to double space.
      Console.Out.NewLine = "\r\n\r\n";
      // Output the lines using the new newline sequence.
      Console.WriteLine("With redefined new line characters:");
      Console.WriteLine();
      foreach (string line in lines)
         Console.WriteLine(line);
   }
}
// The example displays the following output:
//       With the default new line characters:
//       
//       This is the first line.
//       This is the second line.
//       
//       With redefined new line characters:
//       
//       
//       
//       This is the first line.
//       
//       This is the second line.

异常

异常 异常描述
IOException 发生了 I/O 错误。

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。