cint和int32.parse [英] cint and int32.parse

查看:80
本文介绍了cint和int32.parse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉CInt(值),但我不熟悉Int32.Parse(值)。他们似乎也做了同样的事情。这两者之间是否存在很大差异?

最好应用于另一个?


谢谢,

Jim

I''m familiar with CInt(value) but I''m not with Int32.Parse(value). They seem
to do the same thing. Is there a big difference between the two and when
would one be best applied over the other?

Thanks,
Jim

推荐答案

嗨Jim,


根据文档,
$之间的最大区别b $ b CInt / CStr / C< Etc>将变量强制转换为正确的

类型(本例中为整数)的代码是内联编译的。


这使得它的性能(显然)比Int32.Parse更快,因为

没有方法调用。


我不同意上面的语句,因为当我编译代码时

使用CInt(3),CInt()调用转换为

IntegerType.ParseString ...这看起来像是一个方法调用给我

;)甚至IL调用IntegerType.ParseString,所以我不知道这些内联的所有内容。声明。


内置转换函数(C< etc>)在他们尝试转换类型之前做了一些额外的检查。例如,如果你传递

没有,CInt将返回0,但Int32.Parse将抛出ArgumentNullException。


如果你想看看如何胆" CInt工作,打开Reflector和

加载Microsoft.VisualBasic程序集。从那里,深入到
Microsoft.VisualBasic.CompilerServices.IntegerType。该模块中的各种方法

进行转换。


问候,

-Adam。

吉姆在亚利桑那州写道:
Hi Jim,

According to the documentation, the biggest difference between
CInt/CStr/C<Etc> is that the code to coerce the variable to the correct
type (integer in this case) is compiled inline.

This makes it''s performance (apparently) faster than Int32.Parse as
there is no method call.

I disagree with the above statements, because when I compile code that
uses CInt("3"), the CInt() call is converted to
IntegerType.ParseString...and that sure looks like a method call to me
;) Even the IL calls IntegerType.ParseString, so I don''t know about all
these "inline" claims.

The built-in conversion functions (C<etc>) do some extra checks before
they try to cast the type. For example, CInt will return 0 if you pass
Nothing, but Int32.Parse will throw an ArgumentNullException.

If you want to see how the "guts" of CInt works, open up Reflector and
load the Microsoft.VisualBasic assembly. From there, drill down to
Microsoft.VisualBasic.CompilerServices.IntegerType . The various methods
in that module do the conversion.

Regards,
-Adam.

Jim in Arizona wrote:
我熟悉CInt(值),但我不熟悉Int32.Parse(值)。他们似乎也在做同样的事情。两者之间是否存在很大差异,何时最好应用于另一个?

谢谢,
Jim
I''m familiar with CInt(value) but I''m not with Int32.Parse(value). They seem
to do the same thing. Is there a big difference between the two and when
would one be best applied over the other?

Thanks,
Jim



Jim,


说得很简单。


首先是字符少了键入。


其次有Microsoft.Visual Basic转换方法,在某些情况下有一些

附加功能可以提高速度或自动处理你的情况$>
应该需要解析额外命令。


实际上他们应该这样做,我在

IDE旁边找到转换命令VBNet最强大的部分之一。


(你没有提到它,还有一个转换类)


只是我的想法,


Cor
Jim,

To say it very simple.

First of all are it less characters to type.

Second have the Microsoft.Visual Basic conversion methods in some cases some
extras that can improve speed or automatic handling in situations where you
should need with the parse extra commands.

In fact they should do the same, I find the conversions commands beside the
IDE one of the strongest part of VBNet.

(You did not mention it, there is as well a convert class)

Just my thought,

Cor


" Jim in Arizona" < TI ******* @ hotmail.com> schrieb:
"Jim in Arizona" <ti*******@hotmail.com> schrieb:
我熟悉CInt(值),但我不熟悉Int32.Parse(值)。他们似乎做了同样的事情。两者之间是否存在很大差异?
什么时候才能最好地应用于另一个?
I''m familiar with CInt(value) but I''m not with Int32.Parse(value). They
seem to do the same thing. Is there a big difference between the two and
when would one be best applied over the other?




除了其他回复:


VB中的转换运算符

< URL:http://www.panopticoncentral.net/archive/2004/06/07/1200.aspx>


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://classicvb.org/petition/>



In addition to the other replies:

Conversion operators in VB
<URL:http://www.panopticoncentral.net/archive/2004/06/07/1200.aspx>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


这篇关于cint和int32.parse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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