I have some textboxes in my C# windows form application. I want to do the following:
inRed = Convert.ToInt32(tbRed.Text.ToString().Length < 0 ? tbRed.Text = "0" : tbRed.Text);
inGreen = Convert.ToInt32(tbGreen.Text.ToString().Length < 0 ? tbGreen.Text = "0" : tbGreen.Text);
inBlue = Convert.ToInt32(tbBlue.Text.ToString().Length < 0 ? tbBlue.Text = "0" : tbBlue.Text);
inCyan = Convert.ToInt32(tbCyan.Text.ToString().Length < 0 ? tbCyan.Text = "0" : tbCyan.Text);
inMagenta = Convert.ToInt32(tbMagenta.Text.ToString().Length < 0 ? tbMagenta.Text = "0" : tbMagenta.Text);
If the textbox doesn't have a value, enter a 0 and convert to integer, otherwise convert the value of the textbox to integer.
I am getting the following error for inCyan, where the textbox is empty:
Input string was not in a correct format.
How can I achieve what I am looking for?
Length <= 0instead of justLength < 0=. Thanks.NumericUpDowncontrol. It eliminates parsing at all.