SeekOrigin Enumeração
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Especifica a posição num fluxo a usar para a procura.
public enum class SeekOrigin
public enum SeekOrigin
[System.Serializable]
public enum SeekOrigin
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum SeekOrigin
type SeekOrigin =
[<System.Serializable>]
type SeekOrigin =
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SeekOrigin =
Public Enum SeekOrigin
- Herança
- Atributos
Campos
| Name | Valor | Description |
|---|---|---|
| Begin | 0 | Especifica o início de um fluxo. |
| Current | 1 | Especifica a posição atual dentro de um fluxo. |
| End | 2 | Especifica o fim de um fluxo. |
Exemplos
O exemplo seguinte mostra como ler de trás para frente a partir do final do fluxo, e como ler a partir de um ponto especificado no fluxo.
using System;
using System.IO;
public class FSSeek
{
public static void Main()
{
long offset;
int nextByte;
// alphabet.txt contains "abcdefghijklmnopqrstuvwxyz"
using (FileStream fs = new FileStream(@"c:\temp\alphabet.txt", FileMode.Open, FileAccess.Read))
{
for (offset = 1; offset <= fs.Length; offset++)
{
fs.Seek(-offset, SeekOrigin.End);
Console.Write((char)fs.ReadByte());
}
Console.WriteLine();
fs.Seek(20, SeekOrigin.Begin);
while ((nextByte = fs.ReadByte()) > 0)
{
Console.Write((char)nextByte);
}
Console.WriteLine();
}
}
}
// This code example displays the following output:
//
// zyxwvutsrqponmlkjihgfedcba
// uvwxyz
Imports System.IO
Public Class FSSeek
Public Shared Sub Main()
Dim offset As Long
Dim nextByte As Integer
' alphabet.txt contains "abcdefghijklmnopqrstuvwxyz"
Using fs As New FileStream("c:\temp\alphabet.txt", FileMode.Open, FileAccess.Read)
For offset = 1 To fs.Length
fs.Seek(-offset, SeekOrigin.End)
Console.Write(Convert.ToChar(fs.ReadByte()))
Next offset
Console.WriteLine()
fs.Seek(20, SeekOrigin.Begin)
nextByte = fs.ReadByte()
While (nextByte > 0)
Console.Write(Convert.ToChar(nextByte))
nextByte = fs.ReadByte()
End While
Console.WriteLine()
End Using
End Sub
End Class
' This code example displays the following output:
'
' zyxwvutsrqponmlkjihgfedcba
' uvwxyz
Observações
SeekOrigin é usado pelos Seek métodos de Stream, BufferedStream, FileStream, MemoryStream, BinaryWriter, e outras classes. Os Seek métodos tomam um parâmetro de deslocamento que é relativo à posição especificada por SeekOrigin.