System.Console.OpenStandardInput 方法 (Int32)

方法描述

获取设置为指定缓冲区大小的标准输入流。

语法定义(C# System.Console.OpenStandardInput 方法 (Int32) 的用法)

[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)]
public static Stream OpenStandardInput(
	int bufferSize
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
bufferSize System-Int32 内部流缓冲区大小。
返回值 System.IO.Stream 标准输入流。

提示和注释

在通过 SetIn 方法更改标准输出流后,可使用此方法重新获取标准输出流。

注意

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

System.Console.OpenStandardInput 方法 (Int32)例子

下面的示例演示如何使用 OpenStandardInput 属性。

using System;
using System.Text;
using System.IO;

public class Decoder {
    public static void Main() {
        Stream inputStream = Console.OpenStandardInput();
        byte[] bytes = new byte[100];
        Console.WriteLine("To decode, type or paste the UTF7 encoded string and press enter:");
        Console.WriteLine("(Example: \"M+APw-nchen ist wundervoll\")");
        int outputLength = inputStream.Read(bytes, 0, 100);
        char[] chars = Encoding.UTF7.GetChars(bytes, 0, outputLength);
        Console.WriteLine("Decoded string:");
        Console.WriteLine(new string(chars));
    }
}

异常

异常 异常描述
ArgumentOutOfRangeException bufferSize 小于或等于零。

命名空间

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 系统要求。