Equals

Filed Under (kód) by nameless on 23-07-2009

Tagged Under :

Equals:

using System;
 
namespace Program
{
    class Person { }
 
    class EntryPoint
    {
        public static void Main()
        {
            var p1 = new Person();
                                                                                //névtér.típus
            Console.WriteLine("ToString: {0}", p1.ToString());
            Console.WriteLine("Hash code: {0}", p1.GetHashCode()); // egy egész számmal tér vissza, amely egy adott objektumpéldányt azonosít
            Console.WriteLine("Type: {0}", p1.GetType()); 
 
            Person p2 = p1;
            object o = p2;
 
            //Az equals megviszgálja, hogy az értékek ugyan arra a memóriahelyre hivatkoznak-e és ha igen true-val térnek vissza
            if (o.Equals(p1) && p2.Equals(o))
            {
                Console.WriteLine("Same instance!");
            }
            Console.WriteLine();
 
            Console.ReadKey();
        }
    }
}

Post a comment