Reputation: 1275
I have following VB.NET console application code:
Module Module1
Sub Main()
Dim UserInfo As String = "Name: User1"
System.Console.WriteLine(UserInfo)
System.Console.ReadLine()
End Sub
End Module
How to exit the console application when user types anything?
UPDATE: This is the solution:
Module Module1
Sub Main()
Dim UserInfo As String = "Name: User1"
System.Console.WriteLine(UserInfo)
System.Console.ReadKey()
End Sub
End Module
Thanks for all!
Upvotes: 2
Views: 806
Reputation: 1034
Use this one:
System.Console.ReadKey()
It will read a keystroke and return to code. If there is no more code after the System.Console.ReadKey()
line then it will exit the console application.
You can check the value of keystroke being pressed by user and decide whether to do what in next action. You can exit the console application immediate using Exit Sub
.
Upvotes: 3
Reputation: 37710
Use System.Console.ReadKey()
instead of System.Console.ReadLine()
Upvotes: 4
Reputation: 499352
Instead of:
System.Console.ReadLine()
Use:
System.Console.ReadKey()
The former (your code) waits for the user to enter a line.
Upvotes: 2