Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a String to a Short

Current code:

short s;

s = short.Parse(this.txtFields3.Text);

I've gone through with debugging, and can confirm that the txtField3.Text returns an actual value from the form.

Also tried:

s = short.Parse(this.txtFields3.Text, CultureInfo.InvariantCulture);

and,

s = Convert.toInt16(this.textFields3.Text);    

EDIT: The value of the variable I'm trying to put into 's' here is "EMS".

like image 389
James Durman Avatar asked Jul 17 '11 22:07

James Durman


1 Answers

and the value is something that fits into a short?

How about:

short s;
if (!short.TryParse(this.txtFields3.Text, out s)){
    s = 0;
}
like image 186
Jeremy Holovacs Avatar answered Oct 03 '22 23:10

Jeremy Holovacs