C#: Nonzero-based arrays are not CLS-compliant

后端 未结 4 1688
青春惊慌失措
青春惊慌失措 2021-01-02 06:24

I am currently reading Albahari\'s C# 3.0 in a Nutshell and on pg. 241, whilst talking about Array indexing, he says this:

Nonzero-based arr

4条回答
  •  执笔经年
    2021-01-02 07:23

    I addition to what's been said, nonzero-based arrays exist solely to ease transition for existing VB6 code (mainly by the automatic migration tool) since in VB6, array indexing could start from an arbitrary number, not necessarily zero.

    Due to the CLS compliance issue (and other considerations), it's not recommended to ever use them in .NET (even when programming VB.NET). Furthermore, their use is rather restricted. It's easier just to do an offset translation by encapsulating the array inside a class and writing an appropriate index access operator.

提交回复
热议问题