gpt4 book ai didi

asp.net - 如何组合这些 If 语句条件

转载 作者:行者123 更新时间:2023-12-01 06:11:28 25 4
gpt4 key购买 nike

作为一个整体,我对 OOP 很陌生,更不用说 VB 了。我试图通过组合条件将以下 4 行变成 2 行:

ElseIf GA_URI.StartsWith("/home/index") Then
gaCategory = cat_splash

ElseIf GA_URI = "/games" Then
gaCategory = cat_splash

我试过这个:

ElseIf GA_URI.StartsWith("/home/index") And GA_URI = "/games" Then
gaCategory = cat_splash

但是不工作。非常感谢任何帮助

最佳答案

我建议 OrElse所以你可以更有效地短路(不必评估两个表达式):

ElseIf GA_URI.StartsWith("/home/index") OrElse GA_URI = "/games" Then
gaCategory = cat_splash

更新:

Q: Would this work for more than 2 expressions? as I have cases where I may have 3 or more

当然:

ElseIf GA_URI.StartsWith("/home/index") OrElse 
(GA_URI = "/games" OrElse GA_URI = "/foo")
Then
gaCategory = cat_splash
...

你可以继续(括号表达式)但在某个时候Select...Case将是要走的路。

关于asp.net - 如何组合这些 If 语句条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16564444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com