Using return to exit a loop?

后端 未结 5 1240
悲哀的现实
悲哀的现实 2021-01-07 18:27

If I write a for, do, or while loop, is it possible to come out of this with the return keyword?

Eg:

class BreakTest 
{
public static void Main() 
{
         


        
5条回答
  •  旧巷少年郎
    2021-01-07 19:11

    Answer way overdue but return; will exit your whole method (so out of your loop, too) if its return type is void. If it's not, it just won't compile unless your return the method's type.

提交回复
热议问题