共用方式為


NetworkStream.Writeable 屬性

定義

會得到一個值,表示 是否 NetworkStream 可寫。

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

屬性值

true如果資料可以寫入串流;否則,。 false 預設值為 true

範例

在以下程式碼範例中,屬性 CanCommunicate 檢查 Writeable 該屬性以判斷是否 NetworkStream 可寫。

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 類別中推導出才能使用該 Writeable 性質。 若 WriteabletrueNetworkStream 則允許呼叫該 Write 方法。 你也可以透過查看公開可取得CanWrite的財產來判斷 a NetworkStream 是否可寫。

Writeable屬性在初始化時NetworkStream設定。

適用於

另請參閱