SeekOrigin Перечисление
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Задает позицию в потоке, используемую для поиска.
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
- Наследование
- Атрибуты
Имя | Значение | Описание |
---|---|---|
Begin | 0 | Задает начало потока. |
Current | 1 | Задает текущее положение в потоке. |
End | 2 | Задает конец потока. |
В следующем примере показано, как читать назад, начиная с конца потока, и как считывать из указанной точки в потоке.
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
SeekOrigin используется методами Seek
Stream, BufferedStream, FileStream, MemoryStream, BinaryWriterи другими классами. Методы Seek
принимают параметр смещения относительно позиции, заданной параметром SeekOrigin.
Продукт | Версии |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Отзыв о .NET
.NET — это проект с открытым исходным кодом. Выберите ссылку, чтобы оставить отзыв: