在.NET中自动扩展数组?

Joe*_*Fan 2 .net collections perl

.NET是否与Perl数组类似,它们以数字方式编制索引,但会根据需要自动扩展?它会像这样工作:

var x = new DreamArray<string>();

x[6] = "foo";  // x automatically has 7 elements
x[10] = "bar"; // now it has 11
Run Code Online (Sandbox Code Playgroud)

Axe*_*ger 7

使用List<string>而不是数组.您必须打电话List.Add("item")才能添加到列表中.