Get Shallow Hash Code - CSharp System

CSharp examples for System:Hash

Description

Get Shallow Hash Code

Demo Code


using System.Linq;
using System.Collections;
using System;/*from   w w  w .j ava  2s.  c  o  m*/

public class Main{
        public static int GetShallowHashCode(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.GetHashCode() * Prime;
                }
                
                return result;
            }
        }
}

Related Tutorials