コード例 #1
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());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1982, 1, 1));
            System.Console.WriteLine(person.GetBirthdate());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Organwolf/Udemy
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthDate(new DateTime(1987, 08, 04));
            Console.WriteLine(person.GetBirthdate());
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: kippz07/dotnet-learning
        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());
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var person = new Person();
            person.SetBirthdate(new DateTime(1982, 1, 1));
            Console.WriteLine(person.GetBirthdate());

        }
コード例 #6
0
        static void Main(string[] args)
        {
            var person = new Person();

            person.SetBirthdate(new DateTime(1996, 6, 20));
            Console.WriteLine(person.GetBirthdate());
            Console.ReadKey();
        }
コード例 #7
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);
        }
コード例 #8
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());
        }
コード例 #9
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());
        }
コード例 #10
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();
        }
コード例 #11
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();
        }
コード例 #12
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());
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: ejrach/exercises-mosh
        //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
        }
コード例 #14
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();
        }