本文整理匯總了C#中System.IO.WindowsRuntimeStreamExtensions.AsOutputStream方法的典型用法代碼示例。如果您正苦於以下問題:C# WindowsRuntimeStreamExtensions.AsOutputStream方法的具體用法?C# WindowsRuntimeStreamExtensions.AsOutputStream怎麽用?C# WindowsRuntimeStreamExtensions.AsOutputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.WindowsRuntimeStreamExtensions
的用法示例。
在下文中一共展示了WindowsRuntimeStreamExtensions.AsOutputStream方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: BlankPage
//引入命名空間
using System;
using System.IO;
using System.Text;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace ExampleApplication
{
public sealed partial class BlankPage : Page
{
System.Text.UnicodeEncoding ue;
byte[] bytesToWrite;
byte[] bytesToAdd;
int totalBytes;
public BlankPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ue = new System.Text.UnicodeEncoding();
bytesToWrite = ue.GetBytes("example text to write to memory stream");
bytesToAdd = ue.GetBytes("text added through datawriter");
totalBytes = bytesToWrite.Length + bytesToAdd.Length;
}
private async void CreateButton_Click(object sender, RoutedEventArgs e)
{
byte[] bytesRead = new byte[totalBytes];
using (MemoryStream memStream = new MemoryStream(totalBytes))
{
await memStream.WriteAsync(bytesToWrite, 0, bytesToWrite.Length);
DataWriter writer = new DataWriter(memStream.AsOutputStream());
writer.WriteBytes(bytesToAdd);
await writer.StoreAsync();
memStream.Seek(0, SeekOrigin.Begin);
DataReader reader = new DataReader(memStream.AsInputStream());
await reader.LoadAsync((uint)totalBytes);
reader.ReadBytes(bytesRead);
Results.Text = ue.GetString(bytesRead, 0, bytesRead.Length);
}
}
}
}