本文整理汇总了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);
}
}
}
}