แปลงให้ค่าใน value เป็น intiger เพื่อนำไปเช็คต่อไป ป้องกันปัญหาการ shut dum ของโปรแกรม
Ex.
int txtNumber; bool lbConv; lbConv = int.TryParse(this.txtNumber.Text, out txtNumber);
การนำไปใช้
if(txtNumber <= 0) { messageBox.Show(" Number Invalid value ","Check"); }
Convert string to decimal
decimal MPlan = toDecimal(dr["ManpowerPlan"].ToString());
Call function decimal
private decimal toDecimal(string Value) { decimal returnValue; try { returnValue = decimal.Parse(Value); } catch { returnValue = 0; } return returnValue; }
Convert string to int
private int toint(string Value) { int returnValue; try { returnValue = int.Parse(Value); } catch { returnValue = 0; } return returnValue; }
public decimal ConvertDecima(string strData) { bool lbConv; decimal ldcReturn; lbConv = decimal.TryParse(strData, out ldcReturn); return ldcReturn; } public int ConvertInt(string strData) { bool lbConv; int lintReturn; lbConv = int.TryParse(strData, out lintReturn); return lintReturn; }