本文整理汇总了C#中System.IO.BinaryReader.BaseStream属性的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.BaseStream属性的具体用法?C# BinaryReader.BaseStream怎么用?C# BinaryReader.BaseStream使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.BaseStream属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
class BinaryRW
{
static void Main()
{
int i;
const int arrayLength = 1000;
// Create random data to write to the stream.
Random randomGenerator = new Random();
double[] dataArray = new double[arrayLength];
for(i = 0; i < arrayLength; i++)
{
dataArray[i] = 100.1 * randomGenerator.NextDouble();
}
using(BinaryWriter binWriter =
new BinaryWriter(new MemoryStream()))
{
// Write the data to the stream.
Console.WriteLine("Writing data to the stream.");
for(i = 0; i < arrayLength; i++)
{
binWriter.Write(dataArray[i]);
}
// Create a reader using the stream from the writer.
using(BinaryReader binReader =
new BinaryReader(binWriter.BaseStream))
{
try
{
// Return to the beginning of the stream.
binReader.BaseStream.Position = 0;
// Read and verify the data.
Console.WriteLine("Verifying the written data.");
for(i = 0; i < arrayLength; i++)
{
if(binReader.ReadDouble() != dataArray[i])
{
Console.WriteLine("Error writing data.");
break;
}
}
Console.WriteLine("The data was written " +
"and verified.");
}
catch(EndOfStreamException e)
{
Console.WriteLine("Error writing data: {0}.",
e.GetType().Name);
}
}
}
}
}
示例2: Main
//引入命名空间
using System;
using System.IO;
class Class1 {
static void Main(string[] args) {
string[] cma = Environment.GetCommandLineArgs();
if (cma.GetUpperBound(0) >= 1) {
FileStream myFStream = new FileStream(cma[1], FileMode.Open, FileAccess.Read);
BinaryReader binRead = new BinaryReader(myFStream);
binRead.BaseStream.Position = 0x12;
Console.WriteLine(binRead.ReadInt32());
Console.WriteLine(binRead.ReadInt32());
Console.WriteLine(binRead.ReadInt16());
Console.WriteLine(binRead.ReadInt16());
binRead.Close();
myFStream.Close();
}
}
}