什么是在C#中使用标签? [英] What is the use of labels in C#?

查看:243
本文介绍了什么是在C#中使用标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标签和 GOTO s被认为不好的做法,而据我所知,没有任何理由在C#中使用它。

Labels and GOTOs are considered bad practice and as far as I know there is no reason to use it in C#.

什么是在C#中使用标签?

What is the use of labels in C#?

推荐答案

有什么错在自己的标签和跳转的。现在的问题是,人们往往会滥用他们这确实造成了问题。

There is nothing wrong with labels and goto's in themselves. The problem is that people tend to abuse them which does create a problem.

典型用途的标签

OperationStart:
  if ( !TrySomeOperation() ) {
    if ( MaybeFixOperation() ) { 
      goto OperationStart;
    }
  }

您就需要做出安:我喜欢一些断言'吨击中infitite循环,但给予合理的一系列保障,没有什么内在的错误此代码。

You'd need to make some assertions that you couldn't hit an infitite loop, but given a reasonable set of guarantees there's nothing inherently wrong with this code.

这篇关于什么是在C#中使用标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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