开发者

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开发者_JS百科 I'm trying to put into 's' here is "EMS".


and the value is something that fits into a short?

How about:

short s;
if (!short.TryParse(this.txtFields3.Text, out s)){
    s = 0;
}


"EMS" is not a short, so the code will always fail.

Are you sure you understand what you are trying to do? Give us what you really need to do, not what you think you want to do and you will surely be helped.

Update

A short is a data type that represents a number. This is why "EMS" is not a short.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜