本文整理汇总了VB.NET中System.IO.BinaryReader.ReadDouble方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BinaryReader.ReadDouble方法的具体用法?VB.NET BinaryReader.ReadDouble怎么用?VB.NET BinaryReader.ReadDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader 的用法示例。
在下文中一共展示了BinaryReader.ReadDouble方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: BinaryRW
' 导入命名空间
Imports System.IO
Public Class BinaryRW
Shared Sub Main()
Dim i As Integer
Const upperBound As Integer = 1000
' Create random data to write to the stream.
Dim dataArray(upperBound) As Double
Dim randomGenerator As New Random()
For i = 0 To upperBound
dataArray(i) = 100.1 * randomGenerator.NextDouble()
Next i
Dim binWriter As New BinaryWriter(New MemoryStream())
Try
' Write data to the stream.
Console.WriteLine("Writing data to the stream.")
For i = 0 To upperBound
binWriter.Write(dataArray(i))
Next i
' Create a reader using the stream from the writer.
Dim binReader As New BinaryReader(binWriter.BaseStream)
' Return to the beginning of the stream.
binReader.BaseStream.Position = 0
' Read and verify the data.
Try
Console.WriteLine("Verifying the written data.")
For i = 0 To upperBound
If binReader.ReadDouble() <> dataArray(i) Then
Console.WriteLine("Error writing data.")
Exit For
End If
Next i
Console.WriteLine("The data was written and verified.")
Catch ex As EndOfStreamException
Console.WriteLine("Error writing data: {0}.", _
ex.GetType().Name)
End Try
Finally
binWriter.Close()
End Try
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.IO,代码行数:53,代码来源:BinaryReader.ReadDouble
示例2: BinaryReader.ReadDouble()
' 导入命名空间
Imports System.IO
Module Module1
Sub Main()
Dim Stream As FileStream
Try
Stream = New FileStream("test.dat", FileMode.Create)
Catch E As Exception
Console.WriteLine("Error creating test.Dat")
Console.WriteLine("Error {0}", E.Message)
End Try
Dim BinaryStream As New BinaryWriter(Stream)
Dim Age As Integer = 21
Dim Salary As Double = 100000.0
Dim Name As String = "Joe"
Try
BinaryStream.Write(Age)
BinaryStream.Write(Salary)
BinaryStream.Write(Name)
BinaryStream.Close()
Console.WriteLine("Data written to test.Dat")
Catch E As Exception
Console.WriteLine("Error writing to test.Dat")
Console.WriteLine("Error {0}", E.Message)
End Try
'Read
Try
Stream = New FileStream("test.dat", FileMode.Open)
Catch E As Exception
Console.WriteLine("Error opening test.Dat")
Console.WriteLine("Error {0}", E.Message)
End Try
Dim BinaryStreamReader As New BinaryReader(Stream)
Try
Age = BinaryStreamReader.ReadInt32()
Salary = BinaryStreamReader.ReadDouble()
Name = BinaryStreamReader.ReadString()
BinaryStreamReader.Close()
Console.WriteLine("Age: {0}", Age)
Console.WriteLine("Salary: {0}", Salary)
Console.WriteLine("Name: {0}", Name)
Catch E As Exception
Console.WriteLine("Error reading to test.Dat")
Console.WriteLine("Error {0}", E.Message)
End Try
End Sub
End Module
开发者ID:VB程序员,项目名称:System.IO,代码行数:60,代码来源:BinaryReader.ReadDouble
注:本文中的System.IO.BinaryReader.ReadDouble方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论