public CopyTo ( Stream destination, int bufferSize ) : void | ||
destination | Stream | |
bufferSize | int | |
return | void |
using System.IO; class Program { static void Main(string[] args) { byte[] buffer = new byte[] { 0x41, 0x42, 0x43 }; MemoryStream memoryStream = new MemoryStream(buffer); FileStream fileStream = new FileStream("output.txt", FileMode.Create); memoryStream.CopyTo(fileStream); fileStream.Close(); } }
using System.IO; class Program { static void Main(string[] args) { byte[] buffer = new byte[] { 0x41, 0x42, 0x43 }; MemoryStream memoryStream = new MemoryStream(buffer); byte[] output = new byte[3]; memoryStream.CopyTo(output, 0); foreach (byte b in output) { Console.Write((char)b); } } }In the above example, we create a MemoryStream with byte array, then create a byte array(output) of length 3. Then we copy the memory stream data to the byte array using CopyTo method and print byte array value in character form. The MemoryStream class along with the CopyTo method is part of the System.IO namespace in C#.
public CopyTo ( Stream destination, int bufferSize ) : void | ||
destination | Stream | |
bufferSize | int | |
return | void |