public static void ReadProgress(string path, double percent) { using (var fileStream = File.OpenRead(path)) { try { using (var progressStream = new ProgressBarStream(fileStream, percent)) { progressStream.Progress += Display_Progress; var array = new byte[fileStream.Length]; var count = progressStream.Length / 100.0 * percent; progressStream.Read(array, 0, (int)count); var textFromFile = System.Text.Encoding.Default.GetString(array); Console.WriteLine(); Console.WriteLine($"Read text: \n {textFromFile}"); } } catch (Exception e) { ExceptionDisplay.Display(e); } } }
public static void Read(string path, string password) { using (var fileStream = File.OpenRead(path)) { try { using (var protectedStream = new ProtectedStream(fileStream, password)) { var array = new byte[fileStream.Length]; protectedStream.Read(array, 0, array.Length); string textFromFile = System.Text.Encoding.Default.GetString(array); Console.WriteLine($"Text from file: \n {textFromFile}"); } } catch (Exception e) { ExceptionDisplay.Display(e); } } }
static void Main(string[] args) { try { Console.Write($"Euclid Nod = {Euclid.Nod(48, 64, out var ticks)} "); Console.WriteLine($"Elapsed time: {ticks} ticks"); Console.Write($"Binary Nod = {Euclid.BinaryNod(48, 64, out ticks)} "); Console.WriteLine($"Elapsed time: {ticks} ticks"); Console.Write($"Nod of four numbers = {Euclid.Nod(78, 294, 570, 36, out ticks)} "); Console.WriteLine($"Elapsed time: {ticks} ticks"); Console.Write($"Nod with array params = {Euclid.NodWithArrParams(out ticks, 78, 294, 570, 36)} "); Console.WriteLine($"Elapsed time: {ticks} ticks"); } catch (Exception e) { ExceptionDisplay.Display(e); } Console.ReadKey(); }
static void Main(string[] args) { try { var triangle = new Triangle(4.95, 5.244, 3.11); Console.WriteLine(triangle); } catch (Exception e) { ExceptionDisplay.Display(e); } try { var triangle = new Triangle(6.9, 3.9, 4.1); Console.WriteLine(triangle); } catch (Exception e) { ExceptionDisplay.Display(e); } try { var triangle2 = new Triangle(); Console.WriteLine(triangle2); } catch (Exception e) { ExceptionDisplay.Display(e); } try { var triangle3 = new Triangle(9.64, 3.2, 5.972); Console.WriteLine(triangle3); } catch (Exception e) { ExceptionDisplay.Display(e); } try { var triangle4 = new Triangle(0, -2, 10); Console.WriteLine(triangle4); } catch (Exception e) { ExceptionDisplay.Display(e); } if (Triangle.Count != 0) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Count of triangles: {Triangle.Count}"); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Triangles are not defined"); } try { var triangle1 = new Triangle(5, 5, 5); var triangle2 = new Triangle(5, 5, 5); Console.WriteLine($"Sum of triangle1 + triangle2 = {triangle1 + triangle2}"); } catch (Exception e) { ExceptionDisplay.Display(e); } Console.ReadKey(); }