13

It seems that Sum is not defined for IEnumerable<uint> (and other unsigned integers, for that matter)

var s = new int[] { 1, 2, 3 };
s.Sum(); //works fine

var us = new uint[] { 1, 2, 3 };
us.Sum(); //missing method

I would like to know:

  • Have I done something fundamentally wrong/misunderstood the situation?
  • What design decisions might cause the omission of IEnumerable<uint>.Sum()?

MSDN: Enumerable.Sum

dss539
  • 6,804
  • 2
  • 34
  • 64

2 Answers2

6

Just a guess: Because uint is not CLS-compliant. Not sure if that would weigh in their decision to not support it.

PatrickSteele
  • 14,489
  • 2
  • 51
  • 54
0

It might just be an oversight. I'm reminded of ForEach, which is available on Lists but not IEnumerable. I've written .ForEach as an extension method to IEnumerable in at least 3 projects.

mwilson
  • 1,255
  • 12
  • 17
  • 8
    ...Except that `ForEach` was not an oversight. It was deliberately not included in `IEnumerable` extension methods, since those are meant to be functional, and `ForEach` is fundamentally not functional. That said, it **should** be an extension method in IList; see [here](https://connect.microsoft.com/VisualStudio/feedback/details/552410/move-lots-of-helpful-methods-from-list-to-ilist-using-extension-methods) (and upvote!). – BlueRaja - Danny Pflughoeft May 06 '10 at 21:18