Inside Arrays: Grounded at Zero

The introduction of .NET to VB required many changes in how VB worked: One of these changes was the removal of support for non-zero based arrays. Although .NET has a non-zero based single dimension array, it is a different type from the SZArray. If VB were to have supported non-zero-based arrays, it would have had to provide different syntax for SZArrays. Given the framework typically only uses and exposes SZArrays, it would also have meant that the uses for the non-zero based arrays would be limited. That's not to say a better solution wouldn't have been possible.

Rather than have a SZArray be a different type, the CLR team could have instead made all single dimension arrays the same type, and provided zero-based access to members alongside the access offset by the lower-bound. Then, the languages could choose to provide an implementation for either zero-based access, offset-based access, or both.

Unfortunately, that didn't happen, and the real value of adding potential complexities to the languages as they try to support both means of access is questionable. One reason people give for wanting non-zero based arrays include examples where data is stored against years. But in these cases, developers would probably be better off using a sparse array or generic Dictionary(Of TKey, TValue). The lack of support for non-zero based arrays does hit one group of people particularly hard: Those who like to think of arrays as having the first item being one. VB aided and nurtured a generation of developers with Option Base one.

The lack of one-based operations isn't limited to arrays; it's in all framework methods. Many of VB's methods on the other hand are one-based in an attempt to maintain compatibility with previous versions. This leads to a mismatch, such as IntStr being one-based, while String.IndexOf is zero-based. As you work with the framework, you are forced to think in terms of zero-based. Arrays cast as IList or the generic IList(Of T) lose all indication of lower-bound: Item can only be used practically if it's considered to be zero-based. The move from one-based to zero-based isn't a question of functionality; it's a question of perspective. A mix-and-match of one- and zero-based methods rapidly becomes confusing, and the chances of a coding slip up increase. There's a lot to be said for the simplicity of having everything zero-based.

comments powered by Disqus

Featured

  • .NET 11 Preview 5 Focuses on Performance, Productivity and Safer Code

    .NET 11 Preview 5 focuses on under-the-hood runtime performance gains, streamlined APIs and language features that reduce boilerplate, plus built‑in security checks and incremental ASP.NET Core and EF Core improvements aimed at everyday developer productivity.

  • VS Code 1.124 Focuses on Agent Autonomy and Parallel Sessions

    Microsoft's June 2026 VS Code update turns on Autopilot by default and adds background sending for agent sessions.

  • Developing Agentic Systems in .NET: From Concept to Code

    ZioNet founder Alon Fliess previews his Visual Studio Live! San Diego session on building true agentic systems in .NET -- covering the cognitive loop, MCP tool integration, multi-agent orchestration and enterprise hosting and governance with the Microsoft Agent Framework.

  • Mastering AI Development and Building AI Apps with GitHub Copilot

    Two Microsoft experts explain how GitHub Copilot is evolving from a coding assistant into a broader platform for building, customizing and testing AI-powered developer workflows.

Subscribe on YouTube