반응형

http://blog.naver.com/rh0969/166432974


<< GetHashCode() >>
 - 객체를 식별하는 고유한 ID
 - GetHashCode()에 의해서 반환
 - 사용자가 GetHashCode()를 재정의해서 사용할 수 있음


    class HashBase
    {
        private int hash;
        public HashBase(int h)
        {
            hash = h;
        }
    }

    class HashTest
    {
        public static void Main()
        {
            HashBase h1 = new HashBase(10);
            HashBase h2 = new HashBase(10);

            Object obj = new Object();
            string s = "hahaha";
            string t = "hahaha";
            int i = 10000;
            int j = 10000;
            Console.WriteLine("클래스 객체 h1 => " + h1.GetHashCode());
            Console.WriteLine("클래스 객체 h2 => " + h2.GetHashCode());
            Console.WriteLine("Object 객체 obj => " + obj.GetHashCode());
            Console.WriteLine("string 변수 s => " + s.GetHashCode());
            Console.WriteLine("string 변수 t => " + t.GetHashCode());
            Console.WriteLine("int형 변수 i => " + i.GetHashCode());
            Console.WriteLine("int형 변수 j => " + j.GetHashCode());
        }
    }

[출처] [C#]GetHashCode()|작성자 착한남자



반응형

+ Recent posts