使用数组 [英] Working with arrays

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

问题描述

有没有更好的方法来填充数组然后这个


a是一个自动生成的值,总是不同的。

它意味着循环直到数组充满了值,这会有效吗?


int i = 0;

while(array [array.Length-1] == null)

{

array [i] = a;

i ++;

}

is there a better way to fill an array then this

a is a auto generated value, always different.
its meant to loop through until the array is full of values, will this work?

int i=0;
while(array[array.Length-1] == null)
{
array[i] = a;
i++;
}

推荐答案

Thaynann< Th ****** @ discussion.microsoft.com>写道:
Thaynann <Th******@discussions.microsoft.com> wrote:
有没有更好的方法来填充数组然后这个

a是一个自动生成的值,总是不同的。
它意味着循环直到数组充满了值,这会有效吗?

int i = 0;
while(array [array.Length-1] == null)

array [i] = a;
i ++;
}
is there a better way to fill an array then this

a is a auto generated value, always different.
its meant to loop through until the array is full of values, will this work?

int i=0;
while(array[array.Length-1] == null)
{
array[i] = a;
i++;
}




嗯,这会更好:


for(int i = 0; i< array.Length; i ++)

{

array [i] = a;

}


我不认为框架中有任何东西可以填充数组

虽然。


-

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

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



Well, this would be nicer:

for (int i=0; i < array.Length; i++)
{
array[i] = a;
}

I don''t think there''s anything in the framework to fill an array
though.

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


Thaynann,


除了John有时甚至更好一点,

\\\

foreach(arrayType a)in array

{

a = x;

}

///

Cor
Thaynann,

In addition to John sometimes called even a little bit better,

\\\
foreach (arrayType a) in array
{
a = x;
}
///
Cor


不是这样,这段代码什么都不做,你只是一遍又一遍地分配一个本地的

变量(a),数组保持不变。


-

Francisco Padron
www.chartfx.com
Not really, this code does nothing, you are simply assigning a local
variable (a) over and over, the array remains unchanged.

--
Francisco Padron
www.chartfx.com


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

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