Ejemplo n.º 1
0
        public string toString()
        {
            string s = getLabel() + "\n  " + type.ToString();
            string a = (area >= 10000) ? (int)(area / 1000) + "k" : area + "";

            s += " @(img" + imIndex + "; " + x + "; " + y + ")\n"
                 + "  color: " + color.ToString() + "\n"
                 + "  area: " + a + "\n"
                 + "  circularity: " + circularity + "\n";
            return(s);
        }
        private static void aboutEnums()
        {
            Console.WriteLine("Enter shape type you want to calculate the area");
            Console.WriteLine("Please choose [circle/rectangle/square]");
            String input     = Console.ReadLine();
            shape  shapeType = (shape)Enum.Parse(typeof(shape), input);

            double area = 0F;
            double length, breadth;
            string inpLength;


            switch (shapeType)
            {
            case shape.rectangle: Console.WriteLine("Enter the length & breadth");
                Console.WriteLine("Enter Length:");
                inpLength = Console.ReadLine();
                if (!Double.TryParse(inpLength, out length))
                {
                    length = 0F;
                }

                Console.WriteLine("Enter breadth:");
                string inpBreadth = Console.ReadLine();

                if (!Double.TryParse(inpBreadth, out breadth))
                {
                    breadth = 0F;
                }

                area = getArea(length, breadth);

                break;

            case shape.square: Console.WriteLine("Enter side for Square:");
                inpLength = Console.ReadLine();
                if (!Double.TryParse(inpLength, out length))
                {
                    length = 0F;
                }
                area = getArea(length, length);
                break;

            case shape.circle: Console.WriteLine("Enter raidus  for Circle:");
                inpLength = Console.ReadLine();
                if (!Double.TryParse(inpLength, out length))
                {
                    length = 0F;
                }
                area = getArea(length);

                break;
            }

            Console.WriteLine("Area of {0} is {1}", shapeType.ToString(), area);

            Console.WriteLine("=> Information about {0}", shapeType.GetType().Name);
            Console.WriteLine("Underlying storage type: {0}", Enum.GetUnderlyingType(shapeType.GetType()));

            Array enumData = Enum.GetValues(shapeType.GetType());

            Console.WriteLine("This enum has {0} members.", enumData.Length);
        }