Why doesn't .Net have a Set data structure?

后端 未结 9 1712
太阳男子
太阳男子 2021-01-19 00:41

One of my biggest issues dealing with a move from Java to .Net is the fact that there isn\'t a Set interface in .Net. I know there are libraries I could go and download but

相关标签:
9条回答
  • 2021-01-19 01:13

    Do you mean a HashSet?

    0 讨论(0)
  • 2021-01-19 01:20

    I think it's simply an omission by the BCL writers. .NET 3.5 has a HashSet class; for earlier versions, I recommend wrapping a Dictionary<T, object>, with nulls in the value field, to replicate O(1) add, remove and lookup time.

    0 讨论(0)
  • 2021-01-19 01:21

    .NET 3.5 has HashSet which does all set operations.

    0 讨论(0)
  • 2021-01-19 01:22

    As others have noted, there is a HashSet<T>, which is actually just a set.

    The reason it has "hash" in front of it (an implementation detail of the set since it uses hashes to eliminate duplicates) is becase Set is a keyword in VB.NET.

    0 讨论(0)
  • 2021-01-19 01:25

    In .NET 4.0 HashSet will be retrofitted to even implement new ISet interface.

    0 讨论(0)
  • 2021-01-19 01:29

    Maybe because of educational considerations.

    A typical programmer sees a sets as a magical container that just works no matter how many elements are in it.

    If there is no explicit set, a programmer is forced to choose from other types and while doing so reflect on the elements count and appropriate data structure to achieve good performance.

    Just a wild guess.

    0 讨论(0)
提交回复
热议问题