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