【发布时间】:2013-08-21 16:21:19
【问题描述】:
谁能解释一下,为什么我必须使用这个 Code Pattern?
// Create the array to store the CDs.
CD[] cdLibrary = new CD[20];
// Populate the CD library with CD objects.
for (int i=0; i<20; i++)
{ cdLibrary[i] = new CD(); }
我不明白为什么当我调用new CD[20] 时不会发生数组中对象的初始化。好像我在写多余的代码。可以跳过这些步骤之一吗?
【问题讨论】:
-
您可能需要考虑使用 List
而不是数组:stackoverflow.com/questions/434761/…
标签: c# .net arrays initialization