static void Main(string[] args) { // Some code, which will be validate data to constructors: try { Console.WriteLine("Ведите радиус окружности: "); double radius = Double.Parse(Console.ReadLine()); IFigure circle = new Circle { Radius = radius }; var results = new List <ValidationResult>(); var context = new ValidationContext(circle); if (!Validator.TryValidateObject(circle, context, results, true)) { foreach (var error in results) { Console.WriteLine(error.ErrorMessage); } } else { Console.WriteLine(circle.GetArea()); } // The Same code for triangles and some other figures Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { double radius; Console.WriteLine("Введите радиус окружности: "); string input = Console.ReadLine(); bool resultOfParse = double.TryParse(input, out radius); if (resultOfParse == true && radius >= 0 && radius <= double.MaxValue) { IFigure circle = new Circle(radius); Console.WriteLine($"Площадь окружности с радиусом {radius} равна {circle.GetArea()}"); } else { Console.WriteLine("Неверно задан радиус!"); } Console.ReadKey(); // The same code for check triangle or another figure sides }