本文整理汇总了C#中System.IO.BinaryReader.ReadDouble方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadDouble方法的具体用法?C# BinaryReader.ReadDouble怎么用?C# BinaryReader.ReadDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadDouble方法的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: BinaryReader.ReadDouble()
//引入命名空间
using System;
using System.IO;
public class Binary {
public static void Main(string [] args) {
BinaryWriter output = new BinaryWriter(new FileStream("test.dat",FileMode.Create));
output.Write(1);
output.Write(0.01);
output.Close();
BinaryReader input = new BinaryReader(new FileStream("test.dat",FileMode.Open));
Console.WriteLine("{0} ", input.ReadInt32());
Console.WriteLine("{0:F1} ", input.ReadDouble());
input.Close();
}
}