NetworkStream.CanWrite 属性
定义
获取一个值,该值指示 NetworkStream 是否支持写入。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
属性值
如果数据可写入 NetworkStream,则为 true;否则为 false。true if data can be written to the NetworkStream; otherwise, false. 默认值是 true。The default value is true.
示例
下面的代码示例将检查 CanWrite 以验证 NetworkStream 是否可写。The following code example checks CanWrite to verify that the NetworkStream is writable. 然后,它对执行写入操作 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
注解
如果 CanWrite 为 true ,则 NetworkStream 允许对方法的调用 Write 。If CanWrite is true, NetworkStream allows calls to the Write method. FileAccess在构造函数中提供适当的枚举值,以设置的可读性和可写性 NetworkStream 。Provide the appropriate FileAccess enumerated value in the constructor to set the readability and writability of the NetworkStream. CanWrite初始化时设置属性 NetworkStream 。The CanWrite property is set when the NetworkStream is initialized.