NegotiateStream.CanRead 属性

定义

获取一个 Boolean 值,该值指示基础流是否可读。

C#
public override bool CanRead { get; }

属性值

如果已进行身份验证且基础流为可读,则为 true;否则为 false

示例

下面的代码示例演示如何显示此属性的值。

C#
 static void DisplayStreamProperties(NegotiateStream stream)
{
     Console.WriteLine("Can read: {0}", stream.CanRead);
     Console.WriteLine("Can write: {0}", stream.CanWrite);
     Console.WriteLine("Can seek: {0}", stream.CanSeek);
     try
     {
         // If the underlying stream supports it, display the length.
         Console.WriteLine("Length: {0}", stream.Length);
     } catch (NotSupportedException)
     {
             Console.WriteLine("Cannot get the length of the underlying stream.");
     }

     if (stream.CanTimeout)
     {
         Console.WriteLine("Read time-out: {0}", stream.ReadTimeout);
         Console.WriteLine("Write time-out: {0}", stream.WriteTimeout);
     }
}

注解

如果身份验证成功,此属性将返回通过调用 CanRead 基础流上的 属性返回的值。 基础流是在创建 类的 NegotiateStream 实例时指定的。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1