本文整理匯總了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());
}
}
}
}
}