public Write ( byte buffer, int offset, int count ) : void | ||
buffer | byte | |
offset | int | |
count | int | |
return | void |
byte[] byteArray = { 0x10, 0x20, 0x30, 0x40, 0x50 }; MemoryStream memStream = new MemoryStream(); // Set the initial position in memory stream memStream.Position = 0; // Write the byte array to memory stream memStream.Write(byteArray, 0, byteArray.Length); // Display the contents of memory stream Console.WriteLine("Memory stream contents: {0}", Encoding.UTF8.GetString(memStream.ToArray()));
string myString = "Hello World!"; byte[] byteArray = Encoding.UTF8.GetBytes(myString); MemoryStream memStream = new MemoryStream(); // Set the initial position in memory stream memStream.Position = 0; // Write the string to memory stream memStream.Write(byteArray, 0, byteArray.Length); // Display the contents of memory stream Console.WriteLine("Memory stream contents: {0}", Encoding.UTF8.GetString(memStream.ToArray()));In both examples, the System.IO namespace is used to initialize a MemoryStream object and write data to it using the Write method. This method is available in the System.IO.MemoryStream class, which is a part of the .NET Framework class library.
public Write ( byte buffer, int offset, int count ) : void | ||
buffer | byte | |
offset | int | |
count | int | |
return | void |