减少一个foreach [英] decrement a foreach

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

问题描述



有没有办法减少一个foreach循环?


例如


string s = cat;


foreach(char c in s)

//一些如何落后于此

控制台。 WriteLine(c);


结果将是


t

a

c


-

Texeme
http://texeme.com


is there a way to decrement a foreach loop?

for example

string s = "cat";

foreach(char c in s)
//some how it goes backward here
Console.WriteLine(c);

and so the result would be

t
a
c

--
Texeme
http://texeme.com

推荐答案

没有。 foreach内部使用只有MoveNext()的IEnumerator。方法


-vJ

" Elementary Penguin" < SI ***** @ hare.krishna>在消息中写道

新闻:2S *************** @ newsread3.news.pas.earthlin k.net ...
No. foreach internally uses IEnumerator which only has "MoveNext()" method

-vJ
"Elementary Penguin" <si*****@hare.krishna> wrote in message
news:2S***************@newsread3.news.pas.earthlin k.net...

有没有办法减少一个foreach循环?

例如

string s =" cat";

foreach (char c in s)
//一些如何落后于这个
Console.WriteLine(c);

所以结果将是
t



http://texeme.com






为什么你认为你是前进的吗?


你确定你带着

前进,因为整数= 0到Cat.length-1

Cat(i)

next


Cor
Hi,

Why you think you go forwards?

You are sure you go forwards with
for i as integer = 0 to Cat.length-1
Cat(i)
next

Cor


为什么不使用for循环?


string s =" cat"


for(int i = s.Length-1; i> = 0;我 - )

Console.WriteLine(s.Substring(i,1));


-

Mick Doherty
http://dotnetrix.co.uk/nothing.html

" Elementary Penguin" < SI ***** @ hare.krishna>在消息中写道

新闻:2S *************** @ newsread3.news.pas.earthlin k.net ...
Why not use a for loop?

string s = "cat";

for (int i = s.Length-1; i >= 0; i--)
Console.WriteLine(s.Substring(i,1));

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Elementary Penguin" <si*****@hare.krishna> wrote in message
news:2S***************@newsread3.news.pas.earthlin k.net...

有没有办法减少一个foreach循环?

例如

string s =" cat";

foreach (char c in s)
//一些如何落后于这个
Console.WriteLine(c);

所以结果将是
t



http://texeme.com



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

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