Console.WriteLine("Would you like to administer the program?")
Dim answer1 As String = Nothing
If Console.ReadLine = "yes" Then
Console.WriteLine("ok. that's the spirit!")
End If
If Console.ReadLine = "no" Then
Console.WriteLine("ok")
End If
为什么第二个if语句不起作用?
我应该为第二个if语句包含其他内容吗?
答案 0 :(得分:1)
您正在尝试两次读取控制台,因此第二次不同。将Console.ReadLine存储到变量中并进行检查
Console.WriteLine("Would you like to administer the program?")
Dim answer1 As String = Console.ReadLine
If answer1 = "yes" Then
Console.WriteLine("ok. that's the spirit!")
End If
If answer1 = "no" Then
Console.WriteLine("ok")
End If
或者使用开关......
答案 1 :(得分:0)
不清楚的问题?什么不起作用?试试这个;
Console.WriteLine("Would you like to administer the program?")
Select Case Console.ReadLine.ToLower
Case "yes"
Console.WriteLine("ok. that's the spirit!")
Case "no"
Console.WriteLine("ok")
Case else
' Do nothing
End Select