SeekOrigin Enumerazione

Definizione

Specifica la posizione in un flusso da usare per le ricerche.Specifies the position in a stream to use for seeking.

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
Ereditarietà
SeekOrigin
Attributi

Campi

Begin 0

Specifica l'inizio di un flusso.Specifies the beginning of a stream.

Current 1

Specifica la posizione corrente all'interno di un flusso.Specifies the current position within a stream.

End 2

Specifica la fine di un flusso.Specifies the end of a stream.

Esempio

Nell'esempio seguente viene illustrato come leggere all'indietro a partire dalla fine del flusso e come leggere da un punto specificato nel flusso.The following example shows how to read backwards starting at the end of the stream, and how to read from a specified point in the stream.

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(Convert.ToChar(fs.ReadByte()));
            }
            Console.WriteLine();

            fs.Seek(20, SeekOrigin.Begin);

            while ((nextByte = fs.ReadByte()) > 0)
            {
                Console.Write(Convert.ToChar(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

Commenti

SeekOrigin viene usato dai Seek metodi di Stream ,, BufferedStream , FileStream MemoryStream , BinaryWriter e di altre classi.SeekOrigin is used by the Seek methods of Stream, BufferedStream, FileStream, MemoryStream, BinaryWriter, and other classes. I Seek metodi accettano un parametro di offset relativo alla posizione specificata da SeekOrigin .The Seek methods take an offset parameter that is relative to the position specified by SeekOrigin.

Si applica a

Vedi anche