Sdílet prostřednictvím


NetworkStream.Readable Vlastnost

Definice

Získá nebo nastaví hodnotu, která označuje, zda NetworkStream lze číst.

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

Hodnota vlastnosti

true označit, že NetworkStream lze číst; jinak , false. Výchozí hodnota je true.

Příklady

V následujícím příkladu kódu vlastnost zkontroluje CanCommunicateReadable vlastnost, aby určila NetworkStream , zda je čitelný.

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

Poznámky

Chcete-li použít Readable vlastnost, je nutné odvodit z NetworkStream třídy. Pokud Readable je true, NetworkStream umožňuje volání metody Read . Můžete také určit, zda NetworkStream je čitelný kontrolou veřejně přístupné CanRead vlastnosti.

Vlastnost Readable je nastavena při NetworkStream inicializaci.

Platí pro

Viz také