NetworkStream.CanWrite Propriété

Définition

Obtient une valeur indiquant si NetworkStream prend en charge l'écriture.Gets a value that indicates whether the NetworkStream supports writing.

public:
 virtual property bool CanWrite { bool get(); };
public override bool CanWrite { get; }
member this.CanWrite : bool
Public Overrides ReadOnly Property CanWrite As Boolean

Valeur de propriété

Boolean

true si les données peuvent être écrites dans NetworkStream ; sinon, false.true if data can be written to the NetworkStream; otherwise, false. La valeur par défaut est true.The default value is true.

Exemples

L’exemple de code suivant vérifie CanWrite si NetworkStream est accessible en écriture.The following code example checks CanWrite to verify that the NetworkStream is writable. Il effectue ensuite une opération d’écriture sur NetworkStream .It then performs a write operation on the NetworkStream.

// Examples for CanWrite, and CanWrite  
// Check to see if this NetworkStream is writable.
if ( myNetworkStream->CanWrite )
{
   array<Byte>^ myWriteBuffer = Encoding::ASCII->GetBytes(
      "Are you receiving this message?" );
   myNetworkStream->Write( myWriteBuffer, 0, myWriteBuffer->Length );
}
else
{
   Console::WriteLine( "Sorry.  You cannot write to this NetworkStream." );
}
// Examples for CanWrite, and CanWrite

// Check to see if this NetworkStream is writable.
if (myNetworkStream.CanWrite){

     byte[] myWriteBuffer = Encoding.ASCII.GetBytes("Are you receiving this message?");
     myNetworkStream.Write(myWriteBuffer, 0, myWriteBuffer.Length);
}
else{
     Console.WriteLine("Sorry.  You cannot write to this NetworkStream.");
}

' Examples for CanWrite, and CanWrite  
' Check to see if this NetworkStream is writable.
If myNetworkStream.CanWrite Then
   
   Dim myWriteBuffer As Byte() = Encoding.ASCII.GetBytes("Are you receiving this message?")
   myNetworkStream.Write(myWriteBuffer, 0, myWriteBuffer.Length)
Else
   Console.WriteLine("Sorry.  You cannot write to this NetworkStream.")
End If

Remarques

Si CanWrite a true la valeur, NetworkStream autorise les appels à la Write méthode.If CanWrite is true, NetworkStream allows calls to the Write method. Fournissez la FileAccess valeur énumérée appropriée dans le constructeur pour définir la lisibilité et l’accessibilité de NetworkStream .Provide the appropriate FileAccess enumerated value in the constructor to set the readability and writability of the NetworkStream. La CanWrite propriété est définie lorsque NetworkStream est initialisé.The CanWrite property is set when the NetworkStream is initialized.

S’applique à

Voir aussi