C#等于VB IsNumeric? [英] C# equiv to VB IsNumeric ?

查看:102
本文介绍了C#等于VB IsNumeric?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还是我必须迭代字符串并使用Char.IsNumber?

or do I have to iterate the string and use Char.IsNumber ?

推荐答案




您可以使用Convert.ToInt32 / 64,Convert.ToDouble等。


如果参数字符串的值不是,则转换时的类会抛出异常可以转换为这样的目标类型。


它还控制范围(允许的最小值和最大值)并抛出溢出异常。


所以这将毫无例外地工作:

Convert.ToInt32(" -34234")


但是以下将抛出异常:

Convert.ToInt32(" -34234897254072502724525")

-

Cezary Nolewajka

mailto:c。********************* @ no-sp-am-eh-mail.com

删除所有no-sp-am-eh以回复
Hi,

You can use Convert.ToInt32/64, Convert.ToDouble, etc.

The class when converting throws an exception if the parameter string is not in a value that can be converted to such the destination type.

It controls as well the ranges (allowed min and max values) and throws an overflow exception.

So this will work without exception:
Convert.ToInt32 ("-34234")

but the following will throw an exception:
Convert.ToInt32 ("-34234897254072502724525")

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply


您实际上可以访问所有熟悉的VB方法,引用csharp项目中的visual basic

此时我不在家,并且不记得必须将哪个参考添加到您的解决方案才能访问以下命名空间


通常我不使用它,而是尝试捕获,并尝试使用Int32.Parse()转换数字... et


Microsoft.VisualBasic.Information.IsNumeric(价值)


- Dan
You can actually access all your familiar VB method referencing visual basic within your csharp project
at this time I am not at home, and cannot remember which reference has to be added to your solution in order to have access to the below namespaces

Just normally I do not use this, and instead do a try and catch, and try to convert the numbers using Int32.Parse()...et

Microsoft.VisualBasic.Information.IsNumeric(value)

-- Dan


嗨!,


我想我在某个地方读到你不应该使用异常来简单地进行这样的测试 - 提高异常是很昂贵的,因此它们应该只用于检测特殊情况的
。 />

也许有人可以确认/否认这个?

" Cezary Nolewajka" c为C ********************* @ no-sp-am-eh-mail.com>。写在

消息新闻:%2 ****************** @ tk2msftngp13.phx.gbl ...




您可以使用Convert.ToInt32 / 64,Convert.ToDouble等。


转换时的类会抛出异常,如果参数字符串不是
,其值可以转换为目标类型。


它还控制范围(允许的最小值和最大值)并抛出一个

溢出异常。


所以这将毫无例外地工作:

Convert.ToInt32(" -34234" )


但以下内容会抛出异常:

Convert.ToInt32(" -34234897254072502724525")

-

Cezary Nolewajka

mailto:c。********************* @ no-sp -am-eh-mail.com

删除所有no-sp-am-eh以回复

Hi!,

I think I read somewhere that you shouldn''t use exceptions for simple
testing like this - raising exceptions is expensive, so they should only be
used to detect exceptional occurrences.

Maybe somebody can confirm/deny this?
"Cezary Nolewajka" <c.*********************@no-sp-am-eh-mail.com> wrote in
message news:%2******************@tk2msftngp13.phx.gbl...
Hi,

You can use Convert.ToInt32/64, Convert.ToDouble, etc.

The class when converting throws an exception if the parameter string is not
in a value that can be converted to such the destination type.

It controls as well the ranges (allowed min and max values) and throws an
overflow exception.

So this will work without exception:
Convert.ToInt32 ("-34234")

but the following will throw an exception:
Convert.ToInt32 ("-34234897254072502724525")

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply


这篇关于C#等于VB IsNumeric?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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