コード例 #1
0
        public static void Main()
        {
            Type boxType = typeof(Box);

            FieldInfo[] fields = boxType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            Console.WriteLine(fields.Count());

            double inputLength = double.Parse(Console.ReadLine());
            double inputWidth  = double.Parse(Console.ReadLine());
            double inputHeight = double.Parse(Console.ReadLine());

            Box box = new Box(inputLength, inputWidth, inputHeight);

            Console.WriteLine($"Surface Area - {box.CalcSurfaceArea():F2}");
            Console.WriteLine($"Lateral Surface Area - {box.CalcLaterialSurfaceArea():F2}");
            Console.WriteLine($"Volume - {box.CalcVolume():F2}");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            double length = double.Parse(Console.ReadLine());
            double width  = double.Parse(Console.ReadLine());
            double height = double.Parse(Console.ReadLine());

            try
            {
                Box box = new Box(length, width, height);
                Console.WriteLine("Surface Area - {0:f2}", box.CalcSurfaceArea());
                Console.WriteLine("Lateral Surface Area - {0:f2}", box.CalcLateralSurfaceArea());
                Console.WriteLine("Volume - {0:f2}", box.CalcVolume());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }