TimNekkYT

Untitled

Mar 3rd, 2022
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. internal class BinaryFileReader
  5. {
  6.     private static int sum1;
  7.     private static int sum2;
  8.    
  9.     public BinaryFileReader(string path)
  10.     {
  11.         using FileStream fileStream = File.Open(path, FileMode.Open, FileAccess.Read);
  12.         using BinaryReader binaryReader = new BinaryReader(fileStream);
  13.  
  14.         while (true)
  15.         {
  16.             try
  17.             {
  18.                 sum1 += binaryReader.ReadInt16();
  19.             }
  20.             catch (Exception)
  21.             {
  22.                 break;
  23.             }
  24.         }
  25.         fileStream.Seek(0, SeekOrigin.Begin);
  26.  
  27.         while (true)
  28.         {
  29.             try
  30.             {
  31.                 sum2 += binaryReader.ReadInt32();
  32.             }
  33.             catch (Exception)
  34.             {
  35.                 break;
  36.             }
  37.         }
  38.     }
  39.  
  40.     public int GetDifference()
  41.     {
  42.         return Math.Abs(sum1 - sum2);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment