I am making a CMD for my application, and figure I have a trouble when I check `Console.ReadLine != null``
string input = Console.ReadLine();
if(input != nu
-
Instead of just checking for null, try checking if it is empty or null using String.IsNullOrEmpty because, when you do not input anything and press Enter
, you get an empty string which results in an
An unhandled exception of type 'System.IndexOutOfRangeException'
Your updated full code should be as follows
string input = Console.ReadLine();
if (!string.IsNullOrEmpty(input) )
{
SomeFunction(input);
}
- 热议问题