初始化Array对象的数组 [英] initializing array of Array objects

查看:73
本文介绍了初始化Array对象的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码:

private Array [] m_arrays = new Array [3];


生成一个包含3个null Array对象的数组。我错过了什么?

this code:
private Array[] m_arrays = new Array[3];

results in an array of 3 null Array objects. What am I missing?

推荐答案

史蒂夫,


没什么,你只需循环通过创建要存储在数组中的
数组的实例。如果对象是引用类型,则创建这些类型的
数组将默认将所有元素设置为null。

由您来创建实例并且将它们分配给

数组中的元素。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Steve" < ss*@sss.com>在消息中写道

新闻:e9 ************** @ TK2MSFTNGP10.phx.gbl ...
Steve,

Nothing really, you just have to loop through and create instances of
arrays to store in your array. If the object is a reference type, then
arrays created of those types will have all elements set to null by default.
It is up to you to create the instance and assign them to the elements in
the array.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve" <ss*@sss.com> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
此代码:
private Array [] m_arrays = new Array [3];

产生一个包含3个null Array对象的数组。我错过了什么?
this code:
private Array[] m_arrays = new Array[3];

results in an array of 3 null Array objects. What am I missing?



Steve< ss *@sss.com>写道:
Steve <ss*@sss.com> wrote:
这段代码:
private Array [] m_arrays = new Array [3];

产生一个3个null数组对象的数组。我错过了什么?
this code:
private Array[] m_arrays = new Array[3];

results in an array of 3 null Array objects. What am I missing?




绝对没有。你期望它做什么?


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复该组,请不要给我发邮件



Absolutely nothing. What did you expect it to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


它已经初始化了数组(容器)而不是数组的内容。

如果你想用对象上的实例初始化内容那么

你将在数组上循环并手动创建对象。

HTH


Ollie Riches

" Steve" < ss*@sss.com>在消息中写道

新闻:e9 ************** @ TK2MSFTNGP10.phx.gbl ...
it has initialised the array (the container) not the contents of the array.

if you want the contents to be initialised with a instance on an object then
you are going to have loop over the array and create the objects manually.

HTH

Ollie Riches
"Steve" <ss*@sss.com> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
此代码:
private Array [] m_arrays = new Array [3];

产生一个包含3个null Array对象的数组。我错过了什么?
this code:
private Array[] m_arrays = new Array[3];

results in an array of 3 null Array objects. What am I missing?



这篇关于初始化Array对象的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆