本文整理匯總了C#中Windows.Storage.Streams.DataWriter.WriteBoolean方法的典型用法代碼示例。如果您正苦於以下問題:C# DataWriter.WriteBoolean方法的具體用法?C# DataWriter.WriteBoolean怎麽用?C# DataWriter.WriteBoolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.Storage.Streams.DataWriter
的用法示例。
在下文中一共展示了DataWriter.WriteBoolean方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: OnWrite
private async void OnWrite(Object sender, RoutedEventArgs e)
{
// 獲取本地目錄的引用
StorageFolder local = ApplicationData.Current.LocalFolder;
// 創建新文件
StorageFile newFIle = await local.CreateFileAsync("demo.dat", CreationCollisionOption.ReplaceExisting);
// 打開文件流
using(IRandomAccessStream stream = await newFIle.OpenAsync(FileAccessMode.ReadWrite))
{
// 實例化 DataWriter
DataWriter dw = new DataWriter(stream);
// 設置默認編碼格式
dw.UnicodeEncoding = UnicodeEncoding.Utf8;
// 寫入 bool 值
dw.WriteBoolean(true);
// 寫入日期值
DateTime dt = new DateTime(2010, 8, 21);
dw.WriteDateTime(dt);
// 寫入字符串
string str = "測試文本";
// 計算字符串長度
uint len = dw.MeasureString(str);
// 先寫入字符串的長的
dw.WriteUInt32(len);
// 再寫入字符串
dw.WriteString(str);
// 以下方法必須調用
await dw.StoreAsync();
// 解除 DataWriter 與流的關聯
dw.DetachStream();
dw.Dispose();
}
MessageDialog msgDlg = new MessageDialog("保存成功。");
await msgDlg.ShowAsync();
}
示例2: saveState
/// <summary>
/// Saves the current progress state for the current dictionary
/// </summary>
public void saveState()
{
if (string.IsNullOrEmpty(mCrammerDict.StateFile))
throw new Exception("No state file available");
try
{
using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
{
using (DataWriter dataWriter = new DataWriter(memoryStream))
{
dataWriter.WriteInt32(mTotalWords);
dataWriter.WriteInt32(mKnownWords);
dataWriter.WriteInt32(mStart);
dataWriter.WriteInt32(mCurrentWord);
dataWriter.WriteBoolean(mNewWordsInUse);
dataWriter.WriteInt32(mInSystem);
dataWriter.WriteBoolean(mSwapSequence);
dataWriter.WriteBoolean(mReachedEnd);
mNewWordsChamber.saveState(dataWriter);
mFirstChamber.saveState(dataWriter);
mSecondChamber.saveState(dataWriter);
mThirdChamber.saveState(dataWriter);
mFourthChamber.saveState(dataWriter);
mFifthChamber.saveState(dataWriter);
mCompletedChamber.saveState(dataWriter);
IBuffer stateBuffer = dataWriter.DetachBuffer();
string stateString = BinaryBufferConverter.getStringFromBuffer(stateBuffer);
mCrammerDict.setStateFile(stateString);
}
}
}
catch (Exception)
{
// Assume mismatch with chamber-size config and contents of .STA file.
// Delete it so that the dictionary will load successfully next time.
mCrammerDict.removeStateFile();
}
mRestoredState = true;
}
示例3: WriteStatus
private async Task WriteStatus(bool state)
{
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await storageFolder.CreateFileAsync("status.txt", CreationCollisionOption.ReplaceExisting);
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
using (var outputStream = stream.GetOutputStreamAt(0))
{
using (var dataWriter = new DataWriter(outputStream))
{
dataWriter.WriteBoolean(state);
await dataWriter.StoreAsync();
await outputStream.FlushAsync();
}
}
stream.Dispose();
}