Exemple #1
0
        private void SaveTime()
        {
            // Save the information from this file as the variable fileName.
            string fileName = FileLocationManager.GetFileName();

            // If fileName exists...
            if (File.Exists(fileName))
            {
                // Create a new instance of the FileStream class and call it fs. Add to the existing file.
                FileStream fs = new FileStream(fileName, FileMode.Append);
                // Create a new instance of the BinaryWriter class and call it w. Pass fs into this class.
                BinaryWriter w = new BinaryWriter(fs);
                // Write the finalTime to w.
                w.Write(finalTime);
                // Close w.
                w.Close();
                // Close fs.
                fs.Close();
            }
            // Otherwise...
            else
            {
                // Create a new instance of the FileStream class and called it fs. Crate a new file.
                FileStream fs = new FileStream(fileName, FileMode.Create);
                // Create a new instance of the BinaryWriter class and call it w. Pass fs into this class.
                BinaryWriter w = new BinaryWriter(fs);
                // Close w.
                w.Close();
                // Close fs.
                fs.Close();
            }
        }
        private double BestTime()
        {
            // Create a new variable called lowestTime and set it to 0.
            double lowestTime = 0;

            // Create an if statment.
            if (File.Exists(FileLocationManager.GetFileName()))
            {
                // If the file from the variable filePath exists, make a new list and call it timeArray.
                List <double> timeArray = new List <double>();
                // Make an instance of the BinaryReader class, open the File class, go to method GetFileName() in File Location Manager, open the FileMode.
                using (BinaryReader b = new BinaryReader(File.Open(FileLocationManager.GetFileName(), FileMode.Open)))
                {
                    // Create a new variable called pos and set it to 0;
                    double pos = 0;

                    // Create a new variable called length and using the instance of the BinaryReader class, open the BaseStream and get the .Length property.
                    // Cast this so it is a double.
                    double length = (double)b.BaseStream.Length;
                    // While pos is less than length...
                    while (pos < length)
                    {
                        // Create a new variable called v and using the instance of the BinaryReader class, open the method ReadDouble().
                        double v = b.ReadDouble();
                        // Add the time to the array.
                        timeArray.Add(v);

                        //
                        pos += sizeof(double);
                    }
                }

                // Save the minimum time in the timeArray array under the variable lowestTime.
                lowestTime = timeArray.Min();
            }
            // Return the variable lowestTime.
            return(lowestTime);
        }