文本没有出现在vb.net的控制台上

时间:2013-12-05 01:34:51

标签: vb.net

    Console.WriteLine("Choose a city. (if you need help, type list for a list of cities you can destroy.)")
    Console.ReadLine()
    Dim cityList As String = "new york city, carmel, LA, chicago. (we only support detonations for new york city at this point in time.)"

    If Console.ReadLine = "list" Then
        Console.WriteLine(cityList)
        Console.ReadLine()

    End If

'我只是不知道为什么这不起作用

1 个答案:

答案 0 :(得分:2)

您正在拨打Console.ReadLine()两次。你需要删除第一个,或者设置一个等于第一个的变量(并删除第二个),然后检查它是否等于"list"

示例:

Console.WriteLine("Choose a city. (if you need help, type list for a list of cities you can destroy.)")
Dim cityList As String = "new york city, carmel, LA, chicago. (we only support detonations for new york city at this point in time.)"

If Console.ReadLine = "list" Then
    Console.WriteLine(cityList)
    Console.ReadLine()
End If

或存储变量:

Console.WriteLine("Choose a city. (if you need help, type list for a list of cities you can destroy.)")
Dim input As String = Console.ReadLine() ' Store the variable
Dim cityList As String = "new york city, carmel, LA, chicago. (we only support detonations for new york city at this point in time.)"

If input = "list" Then ' Check the stored input
    Console.WriteLine(cityList)
    Console.ReadLine()
End If