如果是空值则赋值0
if (Convert.ToDouble(txtfirstjdjes.Text) + Convert.ToDouble(txtsecondlyjdjes.Text) + Convert.ToDouble(txtthirdjdjes.Text) + Convert.ToDouble(txtfourjdjes.Text) > Convert.ToDouble(lblysjes))
里面有的可能为空,怎么实现这个判断
9 回答
绝地无双
TA贡献1946条经验 获得超4个赞
double num1=string.isnullorempty(txtfirstjdjes.Text.trim())?0:convert.todouble(txtfirstjdjes.Text.trim())
double num2=string.isnullorempty(txtsecondlyjdjes.Text.trim())?0:convert.todouble(txtsecondlyjdjes.Text.trim())
double num3=string.isnullorempty(txtthirdjdjes.Text.trim())?0:convert.todouble(txtthirdjdjes.Text.trim())
double num4=string.isnullorempty(txtfourjdjes.Text.trim())?0:convert.todouble(txtfourjdjes.Text.trim())
萧十郎
TA贡献1815条经验 获得超13个赞
自己写个扩展方法呗
1 public static class Objects
2 {
3 ///
4 /// 将对象安全的转换为int类型(如果转换失败,则为默认值 true:1 false:0)
5 ///
6 ///
7 /// 默认值
8 ///
9 public static int ToSafeInt32(this object o, int defaultValue)
10 { int num = defaultValue;
16 if (o.GetType() == Type.GetType("System.Boolean"))
17 {
18 return (Convert.ToBoolean(o) ? 1 : 0);
19 }
20 try
21 {
22 num = Convert.ToInt32(o);
23 }
24 catch
25 {
26 }
27 return num;
28 } }
- 9 回答
- 0 关注
- 581 浏览
添加回答
举报
0/150
提交
取消