I am getting error int pocet = int.Parse(textBox1.Text);
It says that data have some bad format, but I am writing only natural numbers to TextBox1
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suspect you’ve either got an empty string there, there’s whitespace at the start or end, or you’re writing in the thousands separators.
You can instruct the Int32.Parse method to handle some of those cases like this:
Note the current culture bit at the end is important because the thousands separator will be different depending on the culture the user has their computer set to.
This still won’t handle an empty string though – just check to see if the string is empty before doing the parsing.