SeekOrigin SeekOrigin SeekOrigin SeekOrigin Enum

Definition

Gibt die Position in einem Stream an, der für die Suche verwendet werden soll.Specifies the position in a stream to use for seeking.

public enum class SeekOrigin
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum SeekOrigin
type SeekOrigin = 
Public Enum SeekOrigin
Vererbung
Attribute

Felder

Begin Begin Begin Begin 0

Gibt den Anfang eines Streams an.Specifies the beginning of a stream.

Current Current Current Current 1

Gibt die aktuelle Position innerhalb eines Streams an.Specifies the current position within a stream.

End End End End 2

Gibt das Ende eines Streams an.Specifies the end of a stream.

Beispiele

Das folgende Beispiel zeigt, wie gelesen, am Ende des Streams rückwärts ab, und Lesen aus einem angegebenen Punkt im Stream.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
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

Hinweise

SeekOrigin wird verwendet, durch die Seek Methoden Stream, BufferedStream, FileStream, MemoryStream, BinaryWriter, und andere Klassen.SeekOrigin is used by the Seek methods of Stream, BufferedStream, FileStream, MemoryStream, BinaryWriter, and other classes. Die Seek Methoden akzeptieren einen Offset-Parameter, der relativ zur Position gemäß SeekOrigin.The Seek methods take an offset parameter that is relative to the position specified by SeekOrigin.

Gilt für:

Siehe auch