© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
9 replies
d3adin.

✅ Console Readline accepting empty value.

Hi all,
I'm trying to set console readline to not accept empty value (""). However, I've tried a bunch of different options and I still get "System.FormatException: 'The input string '' was not in a correct format.'
"

Here is my code
do
{
    Console.WriteLine("Player 1, how far away from the city do you want to station the Manticore? ");
    manticoreDistance = Convert.ToInt32(readResult);
} while (manticoreDistance < 0 || manticoreDistance > 100);
Console.Clear();
do
{
    Console.WriteLine("Player 1, how far away from the city do you want to station the Manticore? ");
    manticoreDistance = Convert.ToInt32(readResult);
} while (manticoreDistance < 0 || manticoreDistance > 100);
Console.Clear();

Ideally the goal was to make a loop that displays a message stating that a number needs to be entered.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Console.ReadLine != null
C#CC# / help
3y ago
console.readline and float
C#CC# / help
2y ago
✅ Can't use "Console.ReadLine();"
C#CC# / help
3y ago