[ASK]-将对象转换为整数 [英] [ASK] - Convert object to integer

查看:61
本文介绍了[ASK]-将对象转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家们,我想问您有关将对象转换为整数的最佳方法.这是我的把戏:):

Hi experts, i wanna ask you about the best way convert object to integer. This is my trick :) :

int value = ((IConvertible)ExecuteScalarQuery(partID, sid)).Int32(null));



有没有比我的技巧专家更好的技巧. :confused:



Is there any trick that certainly better than my trick experts.. ?? :confused:

推荐答案

看起来很混乱.我总是调用ToString并使用int.TryParse,这样,如果它不是整数,则不会引发异常.但是ExecuteScalar返回一个int,那么为什么此方法不返回一个?
Looks messy. I always call ToString and use int.TryParse, so that if it''s not an integer, no exception is thrown. But ExecuteScalar returns an int, so why does this method not return one ?


您可以尝试以下

int value =(int)< object value ="> ;;

int value = Convert.ToInt32(< object value =">);
You can try this

int value= (int)<object value="">;
or
int value=Convert.ToInt32(<object value="">);


<pre lang="cs">int test = int.Parse(string.Format("{0}", myobject))



这篇关于[ASK]-将对象转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆