-1

I was just wondering why DateTime.DaysInMonth(int, int) returns an int instead of a ushort? I mean at worst it's 31 (for what the ushort is enough).

What am I missing?

Mitulát báti
  • 2,086
  • 5
  • 23
  • 37
  • We're not using 8 bit CPUs anymore... – KristoferA Oct 02 '16 at 09:58
  • 1
    Consider `byte` is not a number - it is one of memory unit, which can represent a number. So better suggestion will be why not `ushort` – Fabio Oct 02 '16 at 10:00
  • I've marked as duplicate because I believe that the title of this question is different but the core concern is the same. I really believe that answers on the other question will drive OP to a right conclusion! – Matías Fidemraizer Oct 02 '16 at 10:10

1 Answers1

2
  1. The type would not be CLS Compliant.
  2. Typical hardware is optimized for int operations. That might be one of the reasons why operator overloads like +(byte, byte) or +(short, short) return an int and not a byte or short. Its arguable this is the only reason, consistent behavior with previous languages being another. You can check out this question for more details.
Community
  • 1
  • 1
InBetween
  • 32,319
  • 3
  • 50
  • 90