From what I understand, the Length property of a C# System.Array returns an integer value according to the following method signature.
public int Length { get; }
My question then is can the value returned, by calling this method on an instance of an array, ever be negative?
From the signature alone I would normally assume it is a possibility since an "int" can take on both positive and negative values. I guess I'm just hoping I can trust that it will always be 0 or greater and not have to perform a check to see if the value is negative before using it to iterate over the array in a loop or something.
I was wondering if this was an error in design or if I was missing some sort of hidden insight since I probably would have went with a "uint" for the return type.
Edit:
Thank you for pointing me to the reasoning behind the design choice for the int vs uint return type, I was happy to learn that it had a valid rationale behind it.
My question was more related to the "possibility" of EVER getting a negative return value, either from misuse, improper initialization, or some unforeseen circumstances like the one I came across in the question here: Negative Array.Length while using Visual Studio 2019