如:
string sql="select count(1) from table where condition...";
sqlcommand cmd=new sqlcommand(sql,cn);
...
object objNum=cmd.ExecuteSclare(); if(objNum!=null) return int.parse(objNum.ToString());//拆箱 算吗?但我看一篇文章说:“被装过箱的对象才能被拆箱?” 那上面是不是没被装过箱啊?
大家帮我看看,烦啊!
string sql="select count(1) from table where condition...";
sqlcommand cmd=new sqlcommand(sql,cn);
...
object objNum=cmd.ExecuteSclare(); if(objNum!=null) return int.parse(objNum.ToString());//拆箱 算吗?但我看一篇文章说:“被装过箱的对象才能被拆箱?” 那上面是不是没被装过箱啊?
大家帮我看看,烦啊!
本来它是返回查询到的第一行第一列的是吧,这个肯定是值类型的,既然它返回的是Object说明他是装过箱的了
不过我觉得 前提是objNum不为null
object objBox =box1; //装箱
double dubUnBox = (double)objBox; //拆箱
言之有理,这里被我忽略了,这里的ToString()首先就已经破坏了拆箱过程所需的Object了,所以不是拆箱了,而且Parse()只是一个类型转换