Search code examples
c#.netintuint

Why is Array.Length an int, and not an uint


Why is Array.Length an int, and not a uint. This bothers me (just a bit) because a length value can never be negative.

This also forced me to use an int for a length-property on my own class, because when you specify an int-value, this needs to be cast explicitly...

So the ultimate question is: is there any use for an unsigned int (uint)? Even Microsoft seems not to use them.


Solution

  • Unsigned int isn't CLS compliant and would therefore restrict usage of the property to those languages that do implement a UInt.

    See here:

    Framework 1.1

    Introduction to the .NET Framework Class Library

    Framework 2.0

    .NET Framework Class Library Overview