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


C# BinaryReader.ReadChar方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.ReadChar方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadChar方法的具体用法?C# BinaryReader.ReadChar怎么用?C# BinaryReader.ReadChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadChar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i = 0;
        char[] invalidPathChars = Path.InvalidPathChars;
        MemoryStream memStream = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(memStream);

        // Write to memory.
        binWriter.Write("Invalid file path characters are: ");
        for(i = 0; i < invalidPathChars.Length; i++)
        {
            binWriter.Write(invalidPathChars[i]);
        }

        // Create the reader using the same MemoryStream 
        // as used with the writer.
        BinaryReader binReader = new BinaryReader(memStream);

        // Set Position to the beginning of the stream.
        memStream.Position = 0;

        // Read the data from memory and write it to the console.
        Console.Write(binReader.ReadString());
        char[] memoryData = 
            new char[memStream.Length - memStream.Position];
        for(i = 0; i < memoryData.Length; i++)
        {
            memoryData[i] = binReader.ReadChar();
        }
        Console.WriteLine(memoryData);
    }
}
开发者ID:.NET开发者,项目名称:System.IO,代码行数:38,代码来源:BinaryReader.ReadChar

示例2: BinaryReader.ReadChar()

//引入命名空间
using System;
using System.IO;

class MainClass {
    static void Main() {
        using (FileStream fs = new FileStream("test.bin", FileMode.Create)) {
            using (BinaryWriter w = new BinaryWriter(fs)) {
                w.Write(124.23M);
                w.Write("Tstring");
                w.Write("Tstring 2");
                w.Write('!');
            }
        }
        Console.WriteLine("Press Enter to read the information.");
        Console.ReadLine();

        using (FileStream fs = new FileStream("test.bin", FileMode.Open)) {
            using (StreamReader sr = new StreamReader(fs)) {
                Console.WriteLine(sr.ReadToEnd());
                Console.WriteLine();

                fs.Position = 0;
                using (BinaryReader br = new BinaryReader(fs)) {
                    Console.WriteLine(br.ReadDecimal());
                    Console.WriteLine(br.ReadString());
                    Console.WriteLine(br.ReadString());
                    Console.WriteLine(br.ReadChar());
                }
            }
        }
    }
}
开发者ID:C#程序员,项目名称:System.IO,代码行数:33,代码来源:BinaryReader.ReadChar


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