0

I was wondering when working with a HashSet<T> why the property HashSet<T>.Count returns a value of type int instead of uint.

Please correct me when I am wrong, as far as I know it's not possible to have a negative number of entries in a HashSet<T>. So when the smallest returned Count is 0 a uint value would make much more sense in my view.

Does anyone have a clue on this? Or are there other reasons why it's a return value with typeof int?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
JoeT
  • 17
  • 3
  • 4
    I'd hazard a guess that's because [`uint` is not CLS compliant](http://stackoverflow.com/a/6333/1180426), and `HashSet<>` is in a standard platform library. – Patryk Ćwiek Nov 10 '16 at 11:19
  • Thanks @PatrykĆwiek that makes sense. – JoeT Nov 10 '16 at 11:28
  • Some things ARE `int` and your code would be filled with casts between the two. Java doesn't even bother to include `uint`. Also: http://stackoverflow.com/questions/3658560 and http://stackoverflow.com/questions/782629 and http://stackoverflow.com/questions/6301 – Dennis_E Nov 10 '16 at 11:29
  • I think this applies to many many different properties as well, for instance also `List.Count` or `Array.Length`, it´s not specific to `HashSet`. – MakePeaceGreatAgain Nov 10 '16 at 11:32
  • I did not found an already asked question to this specific topic. Maybe it was my fault that I did not searched for a more general kind of question (which is marked as duplicate). – JoeT Nov 10 '16 at 12:43

0 Answers0