What's better for creating distinct data structures: HashSet or Linq's Distinct()?

前端 未结 6 1369
忘了有多久
忘了有多久 2020-12-09 15:37

I\'m wondering whether I can get a consensus on which method is the better approach to creating a distinct set of elements: a C# HashSet or using IEnumera

6条回答
  •  失恋的感觉
    2020-12-09 16:03

    If yor looping through the results of a DbReader adding your resutls to a Hashset would be better than adding it to a List and than doing a Distinct on that. You would save one itteration. (Distinct internally uses a HashSet)

提交回复
热议问题