[C#] int.TryParse用法

  • 1125
  • 0

筆記

 int vPrice;
 bool result = int.TryParse(txtPrice.Text.Trim(), out vPrice);

 if (result)
 {
     vPrice = int.Parse(Others.PreventSQLInjection(txtPrice.Text.Trim()));
     if (vPrice < 0)
     {
         //error message...
         return;
     }
  }
  else
  {
        //error message...
        return;
  }