예제 #1
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != this.GetType())
            {
                return(false);
            }

            Personz person = (Personz)obj;

            return(this.Name == person.Name);
        }
예제 #2
0
        void Print()
        {
            //base
            Personz person = new Personz {
                Name = "Tom"
            };

            Console.WriteLine(person);
            //ToString class
            Clockz clock = new Clockz {
                Hours = 19, Minutes = 45, Seconds = 32
            };

            Console.WriteLine(clock.ToString());
            //ToString
            int    i = 5;
            double b = 3.2;

            Console.WriteLine($"i={i.ToString()}");
            Console.WriteLine($"b={b.ToString()}");

            Personz person1 = new Personz {
                Name = "Tom"
            };
            Personz person2 = new Personz {
                Name = "Bob"
            };
            Personz person3 = new Personz {
                Name = "Tom"
            };
            bool p1Ep2 = person1.Equals(person2);   // false
            bool p1Ep3 = person1.Equals(person3);   // true

            Personz person4 = new Personz {
                Name = "Tom"
            };

            Console.WriteLine(person4.GetType());    // Person
        }