Getting hash of a list of strings regardless of order

后端 未结 5 453
谎友^
谎友^ 2020-11-27 11:27

I would like to write a function GetHashCodeOfList() which returns a hash-code of a list of strings regardless of order. Given 2 lists with the same strings sho

5条回答
  •  [愿得一人]
    2020-11-27 12:06

    A lot less code but maybe the performance isn't as good as the other answers:

    public static int GetOrderIndependentHashCode(this IEnumerable source)    
        => source == null ? 0 : HashSet.CreateSetComparer().GetHashCode(new HashSet(source));
    

提交回复
热议问题