Ejemplo n.º 1
0
            static void Exercise1()
            {
                StartPlan("Exercise1");
                Console.WriteLine("Dar in barname ba vared kardan tool va arz meghdar masahat va mohit mostatil ra hesab mikonim.");
                int Tool, Arz;

                Console.Write("Tool: ");
                //از این دستور برای تبدیل ورودی به عدد صحیح و همچنین کنترل نوع آن استفااده می کنیم
                if (Int32.TryParse(Console.ReadLine(), out Tool) == false)
                {
                    Console.WriteLine("Lotfan meghdar tool ra be sorat adad sahih vared namaeed...");
                }
                ;

                Console.Write("Arz: ");
                if (Int32.TryParse(Console.ReadLine(), out Arz) == false)
                {
                    Console.WriteLine("Lotfan meghdar arz ra be sorat adad sahih vared namaeed...");
                }
                ;

                int Perimeter, Area;

                Area      = Tool * Arz;
                Perimeter = (Tool + Arz) * 2;

                string PrintMsg = "\n\n\n\nTool: " + Tool.ToString() + "\nArz: " + Arz.ToString() +
                                  "\nMohit: " + Perimeter.ToString() + "\nMasahat: " + Area.ToString();

                Console.WriteLine(PrintMsg);
                ExitPlan();
            }
Ejemplo n.º 2
0
        public override string ToString()
        {
            //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-override-the-tostring-method
            //this is what "G" would present if not for "R", is the override ToString of values

            /**When you create a custom class or struct, you should override the ToString
             * method in order to provide information about your type to client code.*/
            string createNew = "";

            //the values of L, W, P, A toString
            createNew += "Length : " + Length.ToString() + "\t";
            createNew += "Width : " + Width.ToString() + "\t";
            createNew += "Perimeter: " + Perimeter.ToString() + "\t";
            createNew += "Area : " + Area.ToString();

            return(createNew);
        }
        public void ComputeCalculations(IBasicShape basicShape)
        {
            NumberOf++;
            Area      += basicShape.GetArea();
            Perimeter += basicShape.GetPerimeter();

            var textToPrint      = TypeOfTheGrouppedShapes.GetProperty("TextToPrint");
            var textToPrintValue = textToPrint?.GetValue(basicShape).ToString();

            TextToPrint = string.Format(textToPrintValue, NumberOf, Area.ToString("#.##"), Perimeter.ToString("#.##"));
        }