It is very, very common to see code like this:
for (int i = 0; i < array.Length; i++)
{
DoSomething(array[i]);
}
The above code makes certain assumptions about arrays (which apparently hold true most of the time, but not all the time). Wouldn't it be more explicit and more forward-compatible to use something like this instead?
for (int i = array.GetLowerBound(0); i <= array.GetUpperBound(0); i++)
{
DoSomething(array[i]);
}
Why is the former format so widely accepted and used?
(I know we could use foreach
, but let's assume that there is some reason that would not work for us in this specific case).