Junior — Middle
Can you explain what is meant by the term 'stream' in the context of programming?
sobes.tech AI
Answer from AI
In programming, a stream is an abstraction for sequential reading or writing of data. Streams allow processing data in parts without loading everything into memory at once.
For example, a stream can represent a file, a network connection, or keyboard input. Using streams, you can read or write data sequentially, which is convenient for working with large volumes of information.
In C#, there are different types of streams, such as FileStream for working with files, MemoryStream for data in memory, and NetworkStream for network operations.
Example of reading a file using a stream:
using (var stream = new FileStream("file.txt", FileMode.Open))
{
byte[] buffer = new byte[1024];
int bytesRead = stream.Read(buffer, 0, buffer.Length);
// process data
}