选择大小写真 [英] Select Case True

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

问题描述

显然,这曾经是 VB6 和 VBA 中短路并执行第一个真实案例的一种方式:

Apparently this used to be a way in VB6 and VBA to short circuit and execute the first true case:

Select Case True
End Select

这是否仍在使用(VB.NET)?

Is this still in use (VB.NET) ?

推荐答案

通常使用此语法代替 If...ElseIf 语句.有些人觉得它更容易阅读.例如:

This syntax is often used instead of an If...ElseIf statement. Some people find it a little easier to read. For example:

Select Case True
    Case testVariable < 0
         Console.Write("You must supply a positive value.")
    Case testVariable > 10
         Console.Write("Please enter a number from 0-10.")
    Case True
         Call DoWork(testVariable)
End Select

答案是肯定的,这在 VB.NET 中仍然有效.使用时要小心,因为它不是标准的编程结构",将来必须维护您的代码的人可能不熟悉它.

The answer is that yes, this still works in VB.NET. Just take care with when you use it, because it's not a "standard programming construct" and may be unfamiliar to people that have to maintain your code in the future.

这篇关于选择大小写真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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