任何人都可以解释,为什么我必须使用这种代码模式?C#初始化数组
// 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]
不会发生对象的数组初始化。看起来我正在编写多余的代码。其中一个步骤可以跳过吗?
你可能想要考虑使用列表而不是数组:http://stackoverflow.com/questions/434761/array-versus-listt-when-to-use-这个 –
User