本文介绍了如何计算循环执行的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! int Totalcount =? foreach(列表中的字符串s) { count ++; } 我怎么知道我的总数是多少?int Totalcount=?foreach (string s in List){count++;}how could i know how much my total count is?推荐答案int Totalcount=0;foreach (string s in List){Totalcount++;} 或者您可以计算列表中更有效的项目(列表中有一个名为 Count 返回列表中项目的计数),因为列表中的每个项目的每个循环都会进行。 欢呼, MarcoOr you could count the items in the list which would be more efficient (The list has a property called Count which returns the count of the items in the list), since the for each loop goes through for every item in the list.cheers,Marco尝试:int totalCount = 0;foreach (string s in List) { totalCount++; }Console.WriteLine(totalCount);或者,你可以使用:Alternatively, you could just use:Console.WriteLine(List.Count);int Totalcount=0;foreach (string s in List){ Totalcount++;}Label1.Text = "For loop has been executed " + Totalcount.ToString() + " times"; Happy Coding! :)Happy Coding!:) 这篇关于如何计算循环执行的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-09 08:05