另一种进行类型转换的方法 [英] Alternative way to do Type Conversion

查看:59
本文介绍了另一种进行类型转换的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此方法

I am currently using this method

System.Convert.ChangeType(object value, Type conversionType, IFormatProvider provider); 



将对象值转换为特定类型。问题是如果无法转换值,则抛出格式异常。因为我需要为1000个条目执行此操作,所以会引发相当多的异常占用我的CPU。



我需要知道是否有替代方式转换到哪里它提供了一个Try ..方法选项,所以我不需要每次都捕获异常。


to convert object values into specific type. The problem is if value cannot be converted then it throws format exception. Since I need to do this for 1000 of entries it throws very considerable amount of exception hogging my CPU.

I have need to know if there is alternate way to convert where it provides a Try.. method option so I need not catch exception each time.

推荐答案

尝试使用 TypeConverter.CanConvertFrom方法 [ ^ ] %29.aspx> System.Convert.ChangeType [ ^ ]但我不确定它会在您的情况下获得性能提升。进行测试并检查它对输入的影响。
try by check using TypeConverter.CanConvertFrom Method[^] before using System.Convert.ChangeType[^] but I'm not sure it will gain performance improvement in your case. do a test and check actually how it affect with your inputs.


这篇关于另一种进行类型转换的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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