本文整理汇总了C#中BinaryReader.ReadDecimal方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadDecimal方法的具体用法?C# BinaryReader.ReadDecimal怎么用?C# BinaryReader.ReadDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadDecimal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
try
{
BinaryWriter dw2 = null;
Stream fs2 = null;
BinaryReader dr2 = null;
FileInfo fil2 = null;
MemoryStream mstr = null;
Decimal dbl2 = 0;
int ii = 0;
Decimal[] dblArr = new Decimal[] {
Decimal.One
,Decimal.Zero
,Decimal.MinusOne
,Decimal.MinValue
,Decimal.MaxValue
,new Decimal(-1000.5)
,new Decimal(-10.0E-40)
,new Decimal(3.4E-40898)
,new Decimal(3.4E-28)
,new Decimal(3.4E+28)
,new Decimal(0.45)
,new Decimal(5.55)
,new Decimal(3.4899E23)
};
strLoc = "Loc_8yfv7";
fil2 = new FileInfo("TestFile.tmp");
fs2 = fil2.Open(FileMode.Create);
dw2 = new BinaryWriter(fs2);
try {
for(ii = 0 ; ii < dblArr.Length ; ii++) {
Console.WriteLine("Writing: "+dblArr[ii]);
dw2.Write(dblArr[ii]);
}
dw2.Flush();
fs2.Close();
strLoc = "Loc_987hg";
fs2 = fil2.Open(FileMode.Open);
dr2 = new BinaryReader(fs2);
Console.WriteLine("Starting Read: ");
try {
for(ii = 0 ; ;ii++) {
iCountTestcases++;
if((dbl2 = dr2.ReadDecimal()) != dblArr[ii]) {
iCountErrors++;
printerr( "Error_298hg! Expected=="+dblArr[ii]+" , got=="+dblArr[ii]);
}
}
} catch (EndOfStreamException) {
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_3298h! Unexpected exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
if(ii != dblArr.Length) {
iCountErrors++;
printerr( "Error_2g767! Incorrect number of elements on filestream");
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_278gy! Unexpected exception, exc=="+exc.ToString());
}
fs2.Close();
fil2.Delete();
strLoc = "Loc_98yss";
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
try {
for(ii = 0 ; ii < dblArr.Length ; ii++)
dw2.Write(dblArr[ii]);
dw2.Flush();
mstr.Position = 0;
strLoc = "Loc_287y5";
dr2 = new BinaryReader(mstr);
try {
for(ii = 0 ; ; ii++) {
iCountTestcases++;
if((dbl2 = dr2.ReadDecimal()) != dblArr[ii]) {
iCountErrors++;
printerr( "Error_948yg! Expected=="+dblArr[ii]+", got=="+dbl2);
}
}
} catch (EndOfStreamException) {
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_238gy! Unexpected exception thrown, exc=="+exc.ToString());
}
iCountTestcases++;
if(ii != dblArr.Length) {
iCountErrors++;
printerr( "Error_289yg! Incorrect number of elements in filestream");
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_298gy! Unexpected exception, exc=="+exc.ToString());
//.........这里部分代码省略.........
示例2: Read
/*
* The binary layout is as follows:
* The first 16 bytes are the sumOfFirst decimal
* The second 16 bytes are the sumOfSecond decimal
* The third 16 bytes are the product decimal
* Then, each 8 bytes alternates between the first and second doubles in the lists
*/
public void Read(BinaryReader binaryReader)
{
if (this.firstList == null)
{
firstList = new List<double>();
}
if (this.secondList == null)
{
secondList = new List<double>();
}
this.sumOfFirst = binaryReader.ReadDecimal();
this.sumOfSecond = binaryReader.ReadDecimal();
long readerLength = binaryReader.BaseStream.Length;
while (binaryReader.BaseStream.Position <= (readerLength - 16))
{
this.firstList.Add(binaryReader.ReadDouble());
this.secondList.Add(binaryReader.ReadDouble());
}
}
示例3: StartListeningTcp
public static void StartListeningTcp()
{
TcpThreadListener listener = new TcpThreadListener(0);
NetworkStream ns = null;
BinaryReader br = null;
try
{
listener.Start();
IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint;
Interlocked.Exchange(ref iPortNumber, ipe.Port);
Console.WriteLine("Using port: {0}", iPortNumber);
m_PortSetEvent.Set();
Socket s = listener.AcceptSocket();
ns = new NetworkStream(s);
br = new BinaryReader( ns );
Decimal iTemp ;
for(int i = 0 ; i < dclArr.Length ; i++)
{
iTemp = br.ReadDecimal();
if(iTemp != dclArr[i])
{
iCountErrors++;
Console.WriteLine( "Error_0000_"+i+"! Expected=="+dclArr[i]+", got=="+iTemp);
}
}
Console.WriteLine("We are done with the listening");
}
catch(Exception e)
{
iCountErrors++ ;
Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace);
m_PortSetEvent.Set();
}
finally
{
if (listener != null)
{
listener.Stop();
}
if (ns != null)
{
ns.Close();
}
if(br != null)
{
br.Close();
}
} //finally
}
示例4: main_Load
private void main_Load(object sender, EventArgs e)
{
//load config
if (File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "config.dat"))
{
FileStream fs = null;
BinaryReader br = null;
try
{
fs = new FileStream(Application.StartupPath + Path.DirectorySeparatorChar + "config.dat", FileMode.Open);
br = new BinaryReader(fs);
dllTool = br.ReadString();
dbpExe = br.ReadString();
interval.Value = br.ReadDecimal();
timer.Interval = (int)interval.Value;
dispWidth.Text = br.ReadString();
dispHeight.Text = br.ReadString();
dispDepth.Text = br.ReadString();
dispMode.SelectedIndex = br.ReadInt32();
log.Items.Add("Loaded Settings");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (br!= null)
br.Close();
if (fs!=null)
fs.Close();
}
}
else
{
//default settings
interval.Value = 250;
timer.Interval = 250;
dispWidth.Text = "640";
dispHeight.Text = "480";
dispDepth.Text = "32";
dispMode.SelectedIndex = 1;
log.Items.Add("No config, using defaults");
}
}
示例5: Read
/*
* The binary layout is as follows:
* The first 16 bytes are the sumOfFirst decimal
* The second 16 bytes are the sumOfSecond decimal
* The third 16 bytes are the product decimal
* Then, each 8 bytes alternates between the first and second doubles in the lists
*/
public void Read(BinaryReader binaryReader)
{
this.n = binaryReader.ReadInt16();
this.mean = binaryReader.ReadDecimal();
this.m2 = binaryReader.ReadDecimal();
this.m3 = binaryReader.ReadDecimal();
this.m4 = binaryReader.ReadDecimal();
}
示例6: Read
/*
* The binary layout is as follows:
* The first 16 bytes are the sumOfSquaresOfFirst decimal
* The second 16 bytes are the sumOfSquaresOfSecond decimal
* The third 16 bytes are the sumOfFirst decimal
* The fourth 16 bytes are the sumOfSecond decimal
* The fifth 16 bytes are the coProduct decimal
* The last 8 bytes are the numberOfRecords long
*/
public void Read(BinaryReader binaryReader)
{
this.sumOfSquaresOfFirst = binaryReader.ReadDecimal();
this.sumOfSquaresOfSecond = binaryReader.ReadDecimal();
this.sumOfFirst = binaryReader.ReadDecimal();
this.sumOfSecond = binaryReader.ReadDecimal();
this.coProduct = binaryReader.ReadDecimal();
this.numberOfRecords = binaryReader.ReadInt64();
}