C#相当于VB.NET“For Each” [英] C# equivalent of VB.NET "For Each"

查看:62
本文介绍了C#相当于VB.NET“For Each”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与VB.Net循环结构相当的C#是什么:


受保护的rbl作为RadioButtonList


Dim li作为ListItem

For each li in rbl.Items


下一页li

What is the C# equivalent to the VB.Net looping structure:

Protected rbl As RadioButtonList

Dim li As ListItem
For Each li In rbl.Items

Next li

推荐答案

相信它或不,它被称为foreach。


John Grandy < johnagrandy-AT-雅虎网络泡沫>在消息中写道

news:eF ************** @ TK2MSFTNGP15.phx.gbl ...
Believe it or not, it''s called "foreach".

"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eF**************@TK2MSFTNGP15.phx.gbl...
什么是C#等价物到VB.Net循环结构:

受保护的rbl作为RadioButtonList

Dim li作为ListItem
For Each li In rbl.Items

>下一个li
What is the C# equivalent to the VB.Net looping structure:

Protected rbl As RadioButtonList

Dim li As ListItem
For Each li In rbl.Items

Next li



C#也有foreach:

http://msdn.microsoft.com/library/de...us/ csref / html /

vclrfTheForeachStatement.asp


任何实现IEnumerable的类都将支持foreach。


-

Ajay Kalra [MVP - VC ++]
aj ***** **@yahoo.com

" John Grandy" < johnagrandy-AT-雅虎网络泡沫>在消息中写道

news:eF ************** @ TK2MSFTNGP15.phx.gbl ...
C# has foreach as well:

http://msdn.microsoft.com/library/de...us/csref/html/
vclrfTheForeachStatement.asp

Any class that implements IEnumerable will support foreach.

--
Ajay Kalra [MVP - VC++]
aj*******@yahoo.com
"John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eF**************@TK2MSFTNGP15.phx.gbl...
什么是C#等价物到VB.Net循环结构:

受保护的rbl作为RadioButtonList

Dim li作为ListItem
For Each li In rbl.Items

>下一页li
What is the C# equivalent to the VB.Net looping structure:

Protected rbl As RadioButtonList

Dim li As ListItem
For Each li In rbl.Items

Next li



2005年3月21日星期一21:38:47 -0500,Ajay Kalra写道:
On Mon, 21 Mar 2005 21:38:47 -0500, Ajay Kalra wrote:
任何实现IEnumerable的类都将支持foreach。
Any class that implements IEnumerable will support foreach.




实际上任何具有返回
$ b的公共GetEnumerator()方法的类$ b IEnumerator实现将支持foreach。该类不需要实现IEnumerable
,只需要GetEnumerator()方法。当这个微妙的差异很重要时,有

次。

-

Tom Porterfield



Actually any class with a public GetEnumerator() method that returns an
IEnumerator implementation will support foreach. The class doesn''t need to
implement IEnumerable, just have the GetEnumerator() method. There are
times when this subtle difference can be important.
--
Tom Porterfield

这篇关于C#相当于VB.NET“For Each”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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