Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Security;
- namespace ConsoleApp3
- {
- class Program
- {
- static Random rnd = new Random();
- static public int Method(int a, int b)
- {
- return rnd.Next(a, b);
- }
- static void Main(string[] args)
- {
- // ReSharper, специфицированная обработка исключений, индексы в рандоме, LINQ в массивах, исключения в файлах
- string str = @"C:\n\input.txt";
- try
- {
- Method(10, 5);
- }
- catch (ArgumentOutOfRangeException e)
- {
- Console.WriteLine(e.Message);
- return;
- }
- string[] fileStrings;
- try
- {
- fileStrings = File.ReadAllLines("../../input.txt");
- }
- catch (IOException e)
- {
- Console.WriteLine(e.Message);
- return;
- }
- int[] arr = new int[fileStrings.Length];
- try
- {
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = int.Parse(fileStrings[i]);
- if (arr[i] < 10)
- throw new ArgumentException("<10.");
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("format.");
- return;
- }
- catch (OverflowException)
- {
- Console.WriteLine("overflow.");
- return;
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- return;
- }
- int max = arr.Max();
- try
- {
- File.WriteAllText("../../output.txt", max.ToString());
- }
- catch (IOException e)
- {
- Console.WriteLine(e.Message);
- return;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement