Get Deep Hash Code - CSharp System

CSharp examples for System:Hash

Description

Get Deep Hash Code

Demo Code


using System.Linq;
using System.Collections;
using System;//from  w  w w. j  a va2s .co  m

public class Main{
        public static int GetDeepHashCode(this object array)
        {
            unchecked
            {
                if (ReferenceEquals(null, array))
                    return 0;
                
                if (!array.GetType().IsArray)
                    return array.GetHashCode();
                
                var result = 0;
                foreach (var element in ToArray(array))
                {
                    if (element == null)
                        continue;
                    
                    result += element.GetDeepHashCode() * Prime;
                }
                
                return result;
            }
        }
}

Related Tutorials