FileStream.CanSeek Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém um valor que indica se o fluxo atual dá suporte à busca.
public:
virtual property bool CanSeek { bool get(); };
public override bool CanSeek { get; }
member this.CanSeek : bool
Public Overrides ReadOnly Property CanSeek As Boolean
Valor da propriedade
true se o fluxo der suporte à busca; false se o fluxo estiver fechado ou se ele FileStream tiver sido construído a partir de um identificador do sistema operacional, como um pipe ou saída para o console.
Exemplos
O exemplo a seguir usa a CanSeek propriedade para verificar se um fluxo dá suporte à busca.
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
//Create the file.
using (FileStream fs = File.Create(path))
{
if (fs.CanSeek)
{
Console.WriteLine("The stream connected to {0} is seekable.", path);
}
else
{
Console.WriteLine("The stream connected to {0} is not seekable.", path);
}
}
}
}
open System.IO
let path = @"c:\temp\MyTest.txt"
// Delete the file if it exists.
if File.Exists path then
File.Delete path
//Create the file.
do
use fs = File.Create path
if fs.CanSeek then
printfn $"The stream connected to {path} is seekable."
else
printfn $"The stream connected to {path} is not seekable."
Imports System.IO
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
' Delete the file if it exists.
If File.Exists(path) Then
File.Delete(path)
End If
'Create the file.
Dim fs As FileStream = File.Create(path)
If fs.CanSeek Then
Console.WriteLine("The stream connected to {0} is seekable.", path)
Else
Console.WriteLine("The stream connected to {0} is not seekable.", path)
End If
fs.Close()
End Sub
End Class
Comentários
Se uma classe derivada de não oferecer Stream suporte à busca, chamará , LengthSetLengthe PositionSeek lançará um NotSupportedException.
Se o fluxo estiver fechado, essa propriedade retornará false.