Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 260351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:20:27+00:00 2026-05-11T22:20:27+00:00

Old question My understanding is that C# has in some sense HashSet and set

  • 0

Old question

My understanding is that C# has in some sense HashSet and set types. I understand what HashSet is. But why set is a separate word? Why not every set is HashSet<Object>?

New question

Why does C# has no generic Set type, similar to Dictionary type? From my point of view, I would like to have a set with standard lookup/addition/deletion performance. I wouldn’t care much whether it is realized with hashes or something else. So why not make a set class that would actually be implemented as a HashSet in this version of C# but perhaps somewhat different in a future version?

Or why not at least interface ISet?

Answer

Learned thanks to everyone who answered below: ICollection implements a lot of what you’d expect from ISet. From my point of view, though, ICollection implements IEnumerable while sets don’t have to be enumerable — example: set of real numbers between 1 and 2 (even more, sets can be generated dynamically). I agree this is a minor rant, as ‘normal programmers’ rarely need uncountable sets.

Ok, I think I get it. HashSet was absolutely meant to be called Set but the word Set is reserved in some sense. More specifically, creators of .NET architecture wanted to have a consistent set (sic!) of classes for different languages. This means that every name of the standard class must not coincide with any keyword in the .NET languages. The word Set, however, is used in VB.NET which is actually case-insensitive (is it?) so unfortunately there is no room for maneuvre there.

Mystery solved 🙂

Epilogue

The new answer by Alex Y. links to the MSDN page which describes the upcoming .NET 4.0 interface ISet which behaves pretty much as I thought it should and is implemented by HashedSet. Happy end.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:20:27+00:00Added an answer on May 11, 2026 at 10:20 pm

    (Your original question about set has been answered. IIRC, “set” is the word with the most different meanings in the English language… obviously this has an impact in computing too.)

    I think it’s fine to have HashSet<T> with that name, but I’d certainly welcome an ISet<T> interface. Given that HashSet<T> only arrived in .NET 3.5 (which in itself was surprising) I suspect we may eventually get a more complete collection of set-based types. In particular, the equivalent of Java’s LinkedHashSet, which maintains insertion order, would be useful in some cases.

    To be fair, the ICollection<T> interface actually covers most of what you’d want in ISet<T>, so maybe that isn’t required. However, you could argue that the core purpose of a set (which is mostly about containment, and only tangentially about being able to iterate over the elements) isn’t quite the same as a collection. It’s tricky. In fact, a truly mathematical set may not be iterable or countable – for instance, you could have “the set of real numbers between 1 and 2.” If you had an arbitrary-precision numeric type, the count would be infinite and iterating over it wouldn’t make any sense.

    Likewise the idea of “adding” to a set doesn’t always make sense. Mutability is a tricky business when naming collections 🙁

    EDIT: Okay, responding to the comment: the keyword set is in no way a legacy to do with Visual Basic. It’s the operation which sets the value of a property, vs get which retrieves the operation. This has nothing to do with the idea of a set as an operation.

    Imagine that instead the keywords were actually fetch and assign, e.g.

    // Not real code!
    public int Foo
    {
        fetch
        {
            return fooField;
        } 
        assign
        {
            fooField = value;
        } 
    }
    

    Is the purpose clear there? Now the real equivalent of that in C# is just

    public int Foo
    {
        get
        {
            return fooField;
        } 
        set
        {
            fooField = value;
        } 
    }
    

    So if you write:

    x = y.Foo;
    

    that will use the get part of the property. If you write:

    y.Foo = x;
    

    that will use the set part.

    Is that any clearer?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This question is over 6 years old and probably no longer has any relevance.)
There is a similar question going around, but it just got the same old
I need debug some old code that uses a Hashtable to store response from
The age old question. Where should you put your business logic, in the database
This might be a old question: Why does IEnumerable<T> inherit from IEnumerable ? This
I found this question in an old question in your website so i thought
Caution: This question is over nine years old! Your best option is to search
I have a bit of an unusual question. I'm running an old DOS game
An old Direct3D book says ...you can achieve an acceptable frame rate with hardware
I have inherited an old crusty PHP application , and I'd like to refactor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.