欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET Razor - VB 邏輯條件

編程邏輯:執(zhí)行基于條件的代碼。

If 條件

VB 允許您執(zhí)行基于條件的代碼。

如需測(cè)試某個(gè)條件,您可以使用 if 語(yǔ)句。if 語(yǔ)句會(huì)基于您的測(cè)試來(lái)返回 true 或 false:

  • if 語(yǔ)句啟動(dòng)代碼塊
  • 條件位于 if 和 then 之間
  • 如果條件為真,則執(zhí)行 if ... then 與 end if 之間的代碼

實(shí)例

@Code
Dim price=50
End Code
<html>
<body>
@If price>30 Then
    @<p>The price is too high.</p>
End If
</body>
</html>

運(yùn)行實(shí)例

Else 條件

if 語(yǔ)句能夠包含 else 條件

else 條件定義條件為 false 時(shí)執(zhí)行的代碼。

實(shí)例

@Code
Dim price=20
End Code
<html>
<body>
@if price>30 then
    @<p>The price is too high.</p>
Else
    @<p>The price is OK.</p>
End If 
</body>
</htmlV>

運(yùn)行實(shí)例

注釋:在上面的例子中,如果價(jià)格不大于 30,則執(zhí)行其余的語(yǔ)句。

ElseIf 條件

可通過(guò) else if 條件來(lái)測(cè)試多個(gè)條件:

實(shí)例

@Code
Dim price=25
End Code
<html>
<body>
@If price>=30 Then
    @<p>The price is high.</p>
ElseIf price>20 And price<30 
    @<p>The price is OK.</p>
Else
    @<p>The price is low.</p>
End If    
</body>
</html>

運(yùn)行實(shí)例

在上面的例子中,如果第一個(gè)條件為 true,則執(zhí)行第一個(gè)代碼塊。

否則,如果下一個(gè)條件為 true,則執(zhí)行第二個(gè)代碼塊。

您能夠設(shè)置任意數(shù)量的 else if 條件。

如果 if 和 else if 條件均不為 true,則執(zhí)行最后一個(gè) else 代碼塊。

Select 條件

select 代碼塊可用于測(cè)試一系列具體的條件:

實(shí)例

@Code
Dim weekday=DateTime.Now.DayOfWeek
Dim day=weekday.ToString()
Dim message=""
End Code
<html>
<body>
@Select Case day
Case "Monday"
    message="This is the first weekday."
Case "Thursday"
    message="Only one day before weekend."
Case "Friday"
    message="Tomorrow is weekend!"
Case Else
    message="Today is " & day
End Select
<p>@message</p>
</body>
</html>

運(yùn)行實(shí)例

"Select Case" 之后是測(cè)試值 (day)。每個(gè)具體的測(cè)試條件以 case 關(guān)鍵詞開(kāi)頭,其后允許任意數(shù)量的代碼行。如果測(cè)試值匹配 case 值,則執(zhí)行代碼行。

select 代碼塊可為其余的情況設(shè)置默認(rèn)的 case (default:),允許在所有 case 均不為 true 時(shí)執(zhí)行代碼。