读书人

C#中 类型强制转换的出现的有关问题

发布时间: 2012-01-23 21:57:28 作者: rapoo

C#中 类型强制转换的出现的问题
代码如下:
long zj;
zj= (tczj + Convert.ToInt64(jl.Text) + Convert.ToInt64(cf.Text));

其中 tczj是个Long 变量...现在给出的提示是 未处理 System.FormatException
输入字符串的格式不正确.

我现在需要的是计算出他们相加的结果..要如何实现?小弟初学C#,求大虾帮忙~!

[解决办法]
zj= Convert.Double(Convert.ToInt64(tczj) + Convert.ToInt64(jl.Text) + Convert.ToInt64(cf.Text));
[解决办法]
jl.Text cf.Text
格式对吗?

[解决办法]
可以换一种方法,用zj=tczj+long.Parse(jl.Text)+long.Parse(cf.Text);
外面用try一下,截获输入非法问题;
[解决办法]
dinoLgrace(淡泊以明志,宁静而致远) ( ) 信誉:100 Blog 加为好友 2007-05-10 15:09:58 得分: 0


zj= Convert.Double(Convert.ToInt64(tczj) + Convert.ToInt64(jl.Text) + Convert.ToInt64(cf.Text));

上述方法应该对吧
好像也可以先定义一个类型转换的函数,然后调用



[解决办法]
把执行zj= (tczj + Convert.ToInt64(jl.Text) + Convert.ToInt64(cf.Text));前jl.Text cf.Text的值贴出来
[解决办法]
zj= (tczj + Convert.ToInt64(jl.Text== " "?0:jl.Text) + Convert.ToInt64(cf.Text== " "?0:cf.Text));

[解决办法]
数据库表格设置中该列设置允许为空可以吗

读书人网 >C#

热点推荐