5 Years
Discussion Span
Last Post by Mike Askew

While easy, that will throw an unhandled exceptioon error if the input string can't be converted to an integer. Using the int.TryParse something like this:

        Console.WriteLine("insert The Number::");
        int c = 0;
        while (!int.TryParse(Console.ReadLine(), out c)) 
            Console.WriteLine("Invalid input");

will make your code much less prone to error. c will contain the converted int after the while loop exits.

Edited by tinstaafl

Votes + Comments
well this is also a way but i told the easiest of all

well this is also a way but i told the easiest of all

Using an easy solution that is also easy to break is a good way to make yourself go bald faster.

Whereas using an easy solution that is hard to break is much more useful.


The easiest solution is not necessarily the best solution. When writing programs you have to consider the "stupid users" factor by making your program as non-breakable as possible. Murphy's Law -- if anythihng can go wrong, it will. Don't expect averyone to enter perfect data -- when testing your program you have to now only test the the right data but also the wrong data. Make an effort to see what breaks your program then make changes to guard against it.

Edited by Ancient Dragon


More easy would be:
string c = Console.ReadLine();
Don't tell the user anything and if the user is so bold and dares to input anything else but an integer, just start to laugh!

Edited by ddanbe


@ddanbe your post is totally wrong Please correct it!!

Before posting test it ! HUH!

Votes + Comments
See post below.

@Saqlainz, there is no right or wrong in programming, multiple techniques in the end lead to the same result.

Only better/worse practices and more/less efficient techniques.

Edited by Mike Askew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.