logo search
CSharp_Prog_Guide

Объявление и передача классов

Если для класса используется фиксированное размещение членов, их можно передавать в неуправляемую функцию DLL. В следующем примере демонстрируется передача последовательно упорядоченных в определении членов класса MySystemTime в функцию GetSystemTime в файле User32.dll. Для функции GetSystemTime используется следующая неуправляемая подпись:

void GetSystemTime(SYSTEMTIME* SystemTime);

В отличие от типов значений для классов всегда используется, по крайней мере, один уровень косвенного обращения.

----

File and Stream I/O

The System.IO namespace contains types that allow synchronous and asynchronous reading and writing on data streams and files.

The following distinctions help clarify the differences between a file and a stream. A file is an ordered and named collection of a particular sequence of bytes having persistent storage. Therefore, with files, one thinks in terms of directory paths, disk storage, and file and directory names. In contrast, streams provide a way to write and read bytes to and from a backing store that can be one of several storage mediums. Just as there are several backing stores other than disks, there are several kinds of streams other than file streams. For example, there are network, memory, and tape streams.

Basic File I/O

The abstract base class Stream supports reading and writing bytes. Stream integrates asynchronous support. Its default implementations define synchronous reads and writes in terms of their corresponding asynchronous methods, and vice versa.

All classes that represent streams inherit from the Stream class. The Stream class and its derived classes provide a generic view of data sources and repositories, isolating the programmer from the specific details of the operating system and underlying devices.

Streams involve these fundamental operations:

Depending on the underlying data source or repository, streams might support only some of these capabilities. For example, NetworkStreams do not support seeking. The CanRead, CanWrite, and CanSeek properties of Stream and its derived classes determine the operations that various streams support.