How to convert linq results to HashSet or HashedSet

前端 未结 9 762
闹比i
闹比i 2020-11-28 05:17

I have a property on a class that is an ISet. I\'m trying to get the results of a linq query into that property, but can\'t figure out how to do so.

Basically, look

9条回答
  •  青春惊慌失措
    2020-11-28 05:47

    As @Joel stated, you can just pass your enumerable in. If you want to do an extension method, you can do:

    public static HashSet ToHashSet(this IEnumerable items)
    {
        return new HashSet(items);
    }
    

提交回复
热议问题