Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1989, 03, 18));
            Console.WriteLine(person.Age);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Person person = new Person();

            person.SetBirthdate(new DateTime(1999, 1, 1));
            Console.WriteLine("The person's birth date is " + person.GetBirthdate());
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var person = new Person(); // Cannot access birthdate using person.birthdate

            person.SetBirthdate(new DateTime(1994, 02, 15));
            System.Console.WriteLine(person.GetBirthdate());
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1985, 10, 17));
            System.Console.WriteLine(person.GetBirthdate());
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthdate());
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var person = new Person();
            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthdate());

        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1996, 6, 20));
            Console.WriteLine(person.GetBirthdate());
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var person = new Person(new DateTime(1991, 05, 10));

            person.SetBirthdate(new DateTime(1991, 05, 10));
            Console.WriteLine(person.GetBirthdate().ToString("dd MMMM yyyy"));
            //// auto-properties
            Console.WriteLine(person.Age);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthdate());
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            // encapsulation - information hiding

            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            System.Console.WriteLine(person.GetBirthdate());
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            var josh = new Person();

            // Console.WriteLine(josh._birthdate); doesn't return anything since this is private field

            josh.SetBirthdate(new DateTime(1992, 11, 12));
            Console.WriteLine(josh.GetBirthdate());
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthdate());

            var customer = new Customer();
            //Amazon.RateCalculator = new RateCalculator();
        }
Ejemplo n.º 13
0
        public static void Main(string[] args)
        {
            var person = new Person();

            // person._birthdate -> if you try to write person dot and then _birthdate (like person._birthdate), it doesn't work 'cause we've set the _birthdate to private

            person.SetBirthdate(new DateTime(1982, 1, 1)); /* notice that we haven't used person.lowercase like usual
                                                            * fields that follow a class. this is because it's a property and we use pascal case */
            Console.WriteLine(person.GetBirthdate());
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            //var john = new Customer();
            //john.setName("john");
            //Console.WriteLine(john.getName());

            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthDate());

            Console.Read();
        }
Ejemplo n.º 15
0
        //An access modifier is a way to control access to a class and/or its members.
        //This creates safety and robustness in our programs.

        //Different types of access modifiers:
        //1. public - accessible form anywhere
        //2. private - accessible only from class. Use this most of the time.
        //3. protected - accessible only from the class and its derived class - try to avoid,
        //      actually violates encapsulation. Use private instead
        //4. internal - accessible only from the same assembly
        //5. protected internal - accessible only from the same assembly or any derived classes. Try to avoid as well.

        static void Main(string[] args)
        {
            //When you create an object here, information hiding (or encapsulation) is when
            //you can't access private data.
            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthdate());


            var customer = new Customer();
            //Amazon.RateCalculator calculator = new Amazon.RateCalculator(); //RateCalculator is not visible since we made the class "internal" instead of public
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1975, 9, 11));
            System.Console.WriteLine(person.GerBirthdate());


            var person2 = new Person2();

            person2.Birthdate = new DateTime(1976, 3, 17);
            System.Console.WriteLine(person2.Age);
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            /* ENCAPSULATION.
             * We can hide some information. The waitress doesn't go and tell the chef how to chop the
             * veg, chop the meat etc. Similarly, the chef doesnt tell the waitress how to clear the tables
             * or be all charming! These things ar outside their responsibility. Each class has only one job and
             * it does it perfectly. We don't want other classes to know about all the details! We hide the details
             * from certain classes: so we can define certain fields as PRIVATE and then give them PUBLIC getters
             * and setters to access them when we need them.
             * */
            // Console.WriteLine();

            var evie = new Person();

            // set the birth date to a value
            evie.SetBirthdate(new DateTime(1993, 06, 23));
            // read the birth date
            Console.WriteLine(evie.GetBirthdate());
            Console.ReadKey();
        }