共用方式為


NetworkStream.Readable 屬性

定義

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

protected:
 property bool Readable { bool get(); void set(bool value); };
protected bool Readable { get; set; }
member this.Readable : bool with get, set
Protected Property Readable As Boolean

屬性值

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

範例

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

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;

ref class MyNetworkStream_Sub_Class: public NetworkStream
{
public:
   MyNetworkStream_Sub_Class( System::Net::Sockets::Socket^ socket, bool ownsSocket )
      : NetworkStream( socket, ownsSocket )
   {
   }

   property bool IsConnected 
   {
      // You can use the Socket method to examine the underlying Socket.
      bool get()
      {
         return this->Socket->Connected;
      }
   }

   property bool CanCommunicate 
   {
      bool get()
      {
         if ( !this->Readable | !this->Writeable )
         {
            return false;
         }
         else
         {
            return true;
         }
      }
   }
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;
            }
        }
    }
Public Class MyNetworkStream_Sub_Class
   Inherits NetworkStream
   
   
   Public Sub New(socket As Socket, ownsSocket As Boolean)
      MyBase.New(socket, ownsSocket)
   End Sub
   
   ' Suppose you wanted a property for determining if Socket is connected. You can use
   ' the protected method 'Socket' to return underlying Socket.
   
   Public ReadOnly Property IsConnected() As Boolean
      Get
         Return Me.Socket.Connected
      End Get
   End Property
   
   ' You could also use public NetworkStream methods 'CanRead' and 'CanWrite'.
   
   Public ReadOnly Property CanCommunicate() As Boolean
      Get
         If Not Me.Readable Or Not Me.Writeable  Then
            Return False
         Else
            Return True
         End If
      End Get
   End Property
    
   Public Shared Sub DoSomethingSignificant()
   End Sub
    ' Do something significant in here

備註

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

初始化 時NetworkStreamReadable設定 屬性。

適用於

另請參閱