Exemplo n.º 1
0
        public static void Main()
        {
            Type chickenType = typeof(Chicken);

            FieldInfo[]  fields  = chickenType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo[] methods = chickenType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
            //Debug.Assert(fields.Where(f => f.IsPrivate).Count() == 2);
            //Debug.Assert(methods.Where(m => m.IsPrivate).Count() == 1);

            string name = Console.ReadLine();
            int    age  = int.Parse(Console.ReadLine());

            try
            {
                Chicken chicken = new Chicken(name, age);
                Console.WriteLine(
                    "Chicken {0} (age {1}) can produce {2} eggs per day.",
                    chicken.Name,
                    chicken.Age,
                    chicken.GetProductPerDay());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            string name = Console.ReadLine();
            int    age  = int.Parse(Console.ReadLine());

            try
            {
                Chicken chicken = new Chicken(name, age);
                Console.WriteLine
                    ($"Chicken {chicken.Name} (age {chicken.Age}) can produce {chicken.GetProductPerDay()} eggs per day.");
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            string name = Console.ReadLine();
            int    age  = int.Parse(Console.ReadLine());

            try
            {
                Chicken chicken = new Chicken(name, age);
                Console.WriteLine(
                    "Chicken {0} (age {1}) can produce {2} eggs per day.",
                    chicken.Name,
                    chicken.Age,
                    chicken.GetProductPerDay());
            }
            catch (ArgumentException exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            // Get Class Type
            Type chickenType = typeof(Chicken);

            // Get Fields and Methods
            FieldInfo[]  fields  = chickenType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo[] methods = chickenType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);

            // Check Privite Fields Length
            Debug.Assert(fields.Where(field => field.IsPrivate).Count() == 2);
            Debug.Assert(methods.Where(method => method.IsPrivate).Count() == 5);

            // Test Data
            string name = Console.ReadLine();
            int    age  = int.Parse(Console.ReadLine());

            // Displays Data
            Chicken chicken = new Chicken(name, age);

            Console.WriteLine($"Chicken {chicken.Name} (age {chicken.Age}) can produce {chicken.GetProductPerDay()} eggs per day.");
        }