当前位置: 首页>>代码示例>>C#>>正文


C# DataWriter.WriteBoolean方法代码示例

本文整理汇总了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();
 }
开发者ID:forehalo,项目名称:UWP-dev,代码行数:35,代码来源:_DataWriter.xaml.cs

示例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;
        }
开发者ID:MartinBjornebye,项目名称:Crammer,代码行数:47,代码来源:PickEngine.cs

示例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();
        }
开发者ID:ebragge,项目名称:SDE,代码行数:17,代码来源:MainPage.xaml.cs


注:本文中的Windows.Storage.Streams.DataWriter.WriteBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。