using System.IO; using Windows.Storage.Streams; MemoryStream memoryStream = new MemoryStream(); byte[] data = { 1, 2, 3, 4, 5 }; memoryStream.Write(data, 0, data.Length); IBuffer buffer = memoryStream.GetWindowsRuntimeBuffer();
using System.IO; using Windows.Storage.Streams; MemoryStream memoryStream = new MemoryStream(); byte[] data = { 1, 2, 3, 4, 5 }; memoryStream.Write(data, 0, data.Length); IBuffer buffer = memoryStream.GetWindowsRuntimeBuffer(); byte[] newData = new byte[buffer.Length]; WindowsRuntimeBufferExtensions.CopyTo(buffer, newData);In this example, after obtaining a Windows Runtime buffer using MemoryStream.GetWindowsRuntimeBuffer, the buffer is copied to a new byte array using the WindowsRuntimeBufferExtensions.CopyTo method. Package library: This method is a part of the System.Runtime.WindowsRuntime.dll library.