选择案例真 [英] Select Case True
本文介绍了选择案例真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
显然这曾经是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屋!
查看全文