对于每个人 [英] For vs. For Each

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

问题描述

这之间有性能差异:


\\\

Dim i As Integer

For i = 0到myObject.Controls.Count - 1

myObject.Controls(i)= ...

下一页

///


和这个:


\\\

Dim ctl As Control

For each ctl in myObject.Controls

ctl = ...

下一页

///


或者每个只是更漂亮?


谢谢,


Eric

Is there a performance difference between this:

\\\
Dim i As Integer
For i = 0 to myObject.Controls.Count - 1
myObject.Controls(i) = ...
Next
///

and this:

\\\
Dim ctl As Control
For Each ctl In myObject.Controls
ctl = ...
Next
///

Or is For Each just "prettier"?

Thanks,

Eric

推荐答案




这是前一段时间讨论过的,你觉得记得几乎没有差别b / b
没有差异,

旁边,这是非常容易检查只是写一个小程序和

迭代两种方式看到结果


最后这是一个VB.net问题,而不是C#问题,没有必要在microsoft.public.dotnet.languages.csh上发布它。 arp

欢呼,

-

Ignacio Machin,

ignacio。 machin AT dot.state.fl.us

佛罗里达州交通局

< an ******* @ discussion.microsoft.com>在消息中写道

新闻:OY ************** @ TK2MSFTNGP11.phx.gbl ...
Hi,

This was discussed a time ago and U think remember that there were almost
no differences,
beside that, this is VERY EASY to check just write an small program and
iterate both ways and see the results

and finally this is a VB.net question, not a C# one, there is no need to
post it on microsoft.public.dotnet.languages.csharp

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<an*******@discussions.microsoft.com> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
是否存在性能差异介于两者之间:

\\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n>对于i = 0到myObject.Controls.Count - 1
myObject.Controls(i )= ...
下一页
///

这:

\\\
Dim ctl As Control
对于每个ctl in myObject.Controls
ctl = ...
下一页
///

或者对于每个只是更漂亮?

谢谢,

Eric
Is there a performance difference between this:

\\\
Dim i As Integer
For i = 0 to myObject.Controls.Count - 1
myObject.Controls(i) = ...
Next
///

and this:

\\\
Dim ctl As Control
For Each ctl In myObject.Controls
ctl = ...
Next
///

Or is For Each just "prettier"?

Thanks,

Eric






这是前段时间讨论过的,你想记得那里几乎没有差别,

除此之外,这非常容易检查一个小程序和

迭代两种方式并查看结果


最后这是一个VB.net问题,而不是C#问题,没有必要将

发布在microsoft.publi上c.dotnet.languages.csharp

欢呼,

-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通局

< an ******* @ discussion.microsoft。 COM>在消息中写道

新闻:OY ************** @ TK2MSFTNGP11.phx.gbl ...
Hi,

This was discussed a time ago and U think remember that there were almost
no differences,
beside that, this is VERY EASY to check just write an small program and
iterate both ways and see the results

and finally this is a VB.net question, not a C# one, there is no need to
post it on microsoft.public.dotnet.languages.csharp

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<an*******@discussions.microsoft.com> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
是否存在性能差异介于两者之间:

\\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n>对于i = 0到myObject.Controls.Count - 1
myObject.Controls(i )= ...
下一页
///

这:

\\\
Dim ctl As Control
对于每个ctl in myObject.Controls
ctl = ...
下一页
///

或者对于每个只是更漂亮?

谢谢,

Eric
Is there a performance difference between this:

\\\
Dim i As Integer
For i = 0 to myObject.Controls.Count - 1
myObject.Controls(i) = ...
Next
///

and this:

\\\
Dim ctl As Control
For Each ctl In myObject.Controls
ctl = ...
Next
///

Or is For Each just "prettier"?

Thanks,

Eric



在VB6中,您应该使用Collection ''为每个''。在这里(.NET)它可能

无关紧要。


我想你应该为每个人使用'',因为它更清洁,可能只要有可能,就使用

优化。 IHMO它看起来也更干净。


- Joris


< an ******* @ discussion.microsoft.com>在消息中写道

新闻:OY ************** @ TK2MSFTNGP11.phx.gbl ...
In VB6 for a Collection you should use ''for each''. Here (.NET) it probably
doesn''t matter.

I suppose you should use ''for each'', because its cleaner and might use
optimizations whenever this will be possible. IHMO it looks cleaner too.

- Joris

<an*******@discussions.microsoft.com> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
是否存在性能差异介于两者之间:

\\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n>对于i = 0到myObject.Controls.Count - 1
myObject.Controls(i )= ...
下一页
///

这:

\\\
Dim ctl As Control
对于每个ctl in myObject.Controls
ctl = ...
下一页
///

或者对于每个只是更漂亮?

谢谢,

Eric
Is there a performance difference between this:

\\\
Dim i As Integer
For i = 0 to myObject.Controls.Count - 1
myObject.Controls(i) = ...
Next
///

and this:

\\\
Dim ctl As Control
For Each ctl In myObject.Controls
ctl = ...
Next
///

Or is For Each just "prettier"?

Thanks,

Eric






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

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