StringBuilder
mySb = new StringBuilder(“1234567890”);
//the length is 10 and the value is “1234567890”
mySb.Length = 7;
//the length is 7 and the value is “1234567”
mySb.Length = 10
//the length is 10 and the value is “1234567”
When you manually decrease the length you also
reduce size of the memory allocation and the extra values are
dropped off. When you increase it the unused portion of the
larger memory is filled with empty values. In the example above
remember you have not created a string, just a StringBuilder
object. When you want to turn it into a string you call the
ToString() method as in this example.
myLabel.Text = mySb.ToString();
C# stream manipulation is also easier and more
elegant than it was in C or C++. Streams include client server
communications as well as communication with hardware or logical
devices. Depending on the type of stream you are accessing,
there are three basic functions. You can write data from a memory
buffer to a stream, you can read data from a stream and you
can ‘seek’, or search for, a specific pattern of
data in a stream.
Winsock is Microsoft’s stream communication
API. Winsock defines a standard service provider interface (SPI)
between the application programming interfaces (API), which
include header and library files in an SDK or DLLs (Winsock
DLL, Ws2.dll) and the protocol stacks. Winsock supports multiple
protocols including IPv6. The Winsock SPI can be used to create
your own transport service provider or to extend an existing
transport SPI by using a Layered Service Provider (LSP).
Microsoft’s has done a good job
of making Winsock API calls backwards compatible and minimizing
versions. But there are differences which you should be aware
of. Every version of Windows after Windows 95 has used Winsock
version 2.2. Patched Windows 95 boxes should be running 2.0.
In most cases the techniques here should work fine. However,
Windows 95 originally shipped with version 1.0 and, only recently,
Windows CE was upgraded from version 1.1 to version 2.2. So
if you are planning to deploy on Windows 95 or CE, be prepared
for some extra research and testing.
NEXT>>
|