VB.Net Case语句中AND运算符的使用 [英] Use of AND operator in VB.Net Case statement
本文介绍了VB.Net Case语句中AND运算符的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用 VB 制作石头剪刀布游戏.我正在寻找一种方法来完成以下工作:
I'm making a rock, paper, scissors game in VB. I'm looking for a way to make the following work:
Select Case userInput
Case = "rock" And computerOutput = "scissors"
Console.WriteLine("You win! You picked " & userInput & ", and the computer picked " & computerOutput & "! Rock beats Scissors, hit enter to continue...")
Console.ReadLine()
userScore = userScore + 1
userInput 和 computerInput 总是石头、纸或剪刀.
userInput and computerInput is always either rock, paper or scissors.
但是当我尝试时,我收到以下错误:
But when I try it I get the following error:
System.InvalidCastException: 'Conversion from string "rock" to type 'Boolean' is not valid.'
我是 VB 新手,所以不确定该怎么做.
I'm newish to VB so not really sure what to do.
推荐答案
你可以按照这个写SELECT CASE
语句:
You can follow this to write SELECT CASE
statement :
Select [ Case ] testexpression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
对于您的代码,您可以这样尝试:
For your code, you can try like this :
Select Case userInput
Case "rock"
if computerOutput = "scissors" then
Console.WriteLine("You win! You picked " & userInput & ", and the computer picked " & computerOutput & "! Rock beats Scissors, hit enter to continue...")
Console.ReadLine()
userScore = userScore + 1
end if
这篇关于VB.Net Case语句中AND运算符的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文