Skip to content

Commit

Permalink
Update ListExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
holos-aafc committed Sep 25, 2024
1 parent 6216dbb commit c2c6b86
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions H.Infrastructure/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ public static double WeightedAverage<T>(this IEnumerable<T> records,
}
}

/// <summary>
/// Hash code depending on the content and order of the elements of the collection
/// </summary>
/// <param name="lst">Collection</param>
/// <typeparam name="T">The type of items in the collection</typeparam>
/// <returns>Hash code</returns>
public static int GetHashCodeByItems<T>(this IEnumerable<T> lst)
{
unchecked
{
int hash = 19;
foreach (T item in lst)
{
hash = hash * 31 + (item != null ? item.GetHashCode() : 1);
}
return hash;
}
}

#endregion

#region Private Methods
Expand Down

0 comments on commit c2c6b86

Please sign in to comment.