CSharp examples for System:Array Null Element
Gets the hash code of all items in the array, or zero when null.
using System.Text; using System.Linq; using System.Collections.Generic; using System.Collections; using System;//www. j av a 2 s . c o m public class Main{ /// <summary> /// Gets the hash code of all items in the array, or zero when null. /// </summary> public static int GetHashCodeOfItemsIfExists(IList array) { if (ReferenceEquals(array, null)) return 0; return array.GetHashCodeOfItems(); } /// <summary> /// Gets the hash code of all items in the array. /// </summary> public static int GetHashCodeOfItems(this IList array) { return array.Cast<object>().Aggregate(0, (current, item) => current ^ (!ReferenceEquals(item, null) ? item.GetHashCode() : 0)); } }