One Line for Getting User Input for Number Computations in C# Like in Python #134995
Unanswered
KofiPhD2019
asked this question in
Ideas
Replies: 1 comment
Note: we never use
It's not natural to provide such a helper for intermediate step without making the whole action a single step: static T ReadFromConsole<T>(string prompt) where T : IParsable<T>
{
Console.Write(prompt);
return T.Parse(Console.ReadLine() ?? throw new InvalidOperationException(), null);
} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In Python, you can use one line get user input while writing the prompt to the user in the console like so:
To do the same in C# you have to write to the console first to prompt the user to enter an input then ReadLine and convert to to int or double or float like so:
Will the developers of C# consider one line to get user input for numerical computations like like in Python like so?
Best Regards,
Kofi
All reactions