-
[C# 4.0 in a Nutshell, pg 539]
What is the stream hierarchy in C Sharp?
- Backing store streams provide the raw data
- Decorator streams provide transparent binary transformations (e.g., encryption)
- Adapters offer methods for dealig in higher-level types such as strings and XML.
-
[C# 4.0 in a Nutshell, pg 540]
Using the following file stream object, create an array of bytes and save them to the file, then read them back.
using (var s = new FileStream("test.txt",
FileMode.Create)){
- s.WriteByte(101);
- byte[] block = { 1, 2, 3, 4, 5 };
- s.Write(block, 0, block.Length);
- Console.WriteLine("s.Position: {0}", s.Position);
- s.Position = 0;
- s.Read(block, 0, block.Length);
-
[C# 4.0 in a Nutshell, pg 542]
In the context of a FileStream, what does the flush method do?
Forces any internally buffered data to be written immediately. Flush is called when the stream is closed.
-
[C# 4.0 in a Nutshell, pg 545]
Using the diagram, which FileMode would you use to append to an existing file?
FileMode.Open
-
[C# 4.0 in a Nutshell, pg 546]
Is it possible for more than one user or process to simultaneously read and write to the same file?
- Yes, the FileStream class has the two methods:
- public virtual void Lock(long position, long length)
- public virtual void Unlock(long position, long length)
-
[C# 4.0 in a Nutshell, pg 547]
Introduced in Framework 3.5, what are the two kind of pipes of a PipeStream?
- Anonymous pipes for one-way communication between a parent and child process on the same computer.id
- Named pipes for two-way communication between two processes or computers on a Windows network.
-
[C# 4.0 in a Nutshell, pg 547]
Using the following code that sends a byte across a stream, write the corresponding Client that sends another byte back across.
using (var s = new NamedPipeServerStream("pipedream")){
s.WaitForConnection();
s.WriteByte(100);
Console.WriteLine("{0}data received: {1}", Environment.NewLine, s.ReadByte());}
- using (var s = new NamedPipeClientStream("pipedream")){
- s.Connect();
- Console.WriteLine(s.ReadByte());
- s.WriteByte(200);}
-
[C# 4.0 in a Nutshell, pg 549]
Using the PipeStream example, what mechanism could be used for messages longer than one byte?
Using the message transmission mode, a party calling Read can know when the message is complete by checking the IsMessageComplete property.
|
|