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

There's an old question that asks this very thing, but a lot has changed
Okay, I might be asking an age old question, but I did not get
Question is old and i guess has no 100% right answer. But would like
[ Old question title used to be ARC is set to YES, but xcode
I have this old question but no answer works for me from online, the
I know this is an old question, but I have spend any hours on
this is probably an old question, but I've read through articles about usb barcode
OLD QUESTION, SEE BELOW FOR THE UPDATED VERSION My development environment is not the
I think is an old question but I don't get it. I have a
I've noticed my old question has gotten closed due to lack of details and

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.