NetworkStream.Readable 屬性

定義

取得或設定值,指出是否可以讀取 NetworkStream

C#
protected bool Readable { get; set; }

屬性值

若要指示可以讀取 NetworkStream,則為 true,否則為 false。 預設值是 true

範例

在下列程式代碼範例中,屬性會 CanCommunicate 檢查 屬性, Readable 以判斷 是否 NetworkStream 可讀取 。

C#
using System;
using System.Net;
using System.Net.Sockets;

public class MyNetworkStream_Sub_Class : NetworkStream
{

    public MyNetworkStream_Sub_Class(Socket socket, bool ownsSocket) :
        base(socket, ownsSocket)
    {
    }
    // You can use the Socket method to examine the underlying Socket.
    public bool IsConnected
    {
        get
        {
            return this.Socket.Connected;
        }
    }

    public bool CanCommunicate
    {
        get
        {
            if (!this.Readable | !this.Writeable)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }

備註

您必須衍生自 類別, NetworkStream 才能使用 Readable 屬性。 如果 ReadabletrueNetworkStream 則允許呼叫 Read 方法。 您也可以藉由檢查可公開存取CanRead的屬性來判斷 NetworkStream 是否可讀取 。

初始化 時NetworkStreamReadable設定 屬性。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 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

另請參閱