VB转换关键字和.NET转换例程 [英] VB Conversion Keywords And .NET Conversion Routines

查看:59
本文介绍了VB转换关键字和.NET转换例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




只是想知道
之间是否有任何速度差异
VB转换关键词如CInt,Clng,CStr, CDbl,CBool​​等

..NETs Convert.To< ...>方法。


哪个更好用,为什么?


Thanx

rawCoder


Hi,

Just wanted to know if there is any speed difference between

VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc.
..NETs Convert.To<...> methods.

And which is better to be used and why ?

Thanx
rawCoder


推荐答案

就我个人而言,我使用像Convert.ToInt32()这样的通用.NET方法而不是

CInt ()等。这使您的程序与其他.NET

语言更加一致,包括C#。一些VB遗留转换方法具有

向后兼容行李。我不记得具体细节,但最好直接打电话到CLR,这样你才能确切地知道你得到了什么,

写新代码。当转换传统的VB6代码时,那就是当你使用VB版本时,至少在转换的早期迭代中使用VB版本。


在我看来,你能想到的最好的是CInt()除了调用Convert.ToInt32()之外什么都不做。至少,这是一个额外的电话。我只是很快就会避免这种情况。


另一个经常被忽视的问题是,在编写新代码时,最好是

使用AndAlso / OrElse而不是And / Or,这样你就可以摆脱VB中最令人讨厌的功能之一:缺乏短路评估。再一次,当你试图彻底改变传统的VB6

代码时,或者在你真正做不到的极少数情况下,你会坚持使用和/或。想要短路

评价。


--BOB


" rawCoder" < RA ****** @ hotmail.com>在消息中写道

news:eh ************* @ TK2MSFTNGP15.phx.gbl ...
Personally I use the generic .NET methods like Convert.ToInt32() instead of
CInt(), etc. This makes your programs more congruent with other .NET
languages, including C#. Some of the VB legacy conversion methods have
backward compatibility baggage. I don''t recall the specifics, but it''s best
to make direct calls into the CLR so you know exactly what you''re getting,
when writing new code. When converting legacy VB6 code, that''s when you''d
use the VB versions, at least in early iterations of the conversion.

The best you can hope for, it seems to me, is that CInt() does nothing more
than call Convert.ToInt32(); at minimum, that''s an extra call. I''d just as
soon avoid that.

Another oft-overlooked issue is that when writing new code it''s better to
use AndAlso / OrElse rather than And/Or, so that you get rid of one of VB''s
most annoying features: lack of short-circuit evaluation. Again, you''d
stick with And / Or when trying to get a clean conversion of legacy VB6
code, or on those rare occasions when you actually don''t want short-circuit
evaluation.

--Bob

"rawCoder" <ra******@hotmail.com> wrote in message
news:eh*************@TK2MSFTNGP15.phx.gbl...


只想知道VB转换之间是否有任何速度差异如CInt,Clng,CStr,CDbl,CBool​​等关键词
.NETs Convert.To< .. >方法。

哪个更好用,为什么?

Thanx
rawCoder
Hi,

Just wanted to know if there is any speed difference between

VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc.
.NETs Convert.To<...> methods.

And which is better to be used and why ?

Thanx
rawCoder



我个人使用通用的.NET方法,比如Convert.ToInt32()而不是

CInt()等。这使你的程序更加与其他.NET一致

语言,包括C#。一些VB遗留转换方法具有

向后兼容行李。我不记得具体细节,但最好直接打电话到CLR,这样你才能确切地知道你得到了什么,

写新代码。当转换传统的VB6代码时,那就是当你使用VB版本时,至少在转换的早期迭代中使用VB版本。


在我看来,你能想到的最好的是CInt()除了调用Convert.ToInt32()之外什么都不做。至少,这是一个额外的电话。我只是很快就会避免这种情况。


另一个经常被忽视的问题是,在编写新代码时,最好是

使用AndAlso / OrElse而不是And / Or,这样你就可以摆脱VB中最令人讨厌的功能之一:缺乏短路评估。再一次,当你试图彻底改变传统的VB6

代码时,或者在你真正做不到的极少数情况下,你会坚持使用和/或。想要短路

评价。


--BOB


" rawCoder" < RA ****** @ hotmail.com>在消息中写道

news:eh ************* @ TK2MSFTNGP15.phx.gbl ...
Personally I use the generic .NET methods like Convert.ToInt32() instead of
CInt(), etc. This makes your programs more congruent with other .NET
languages, including C#. Some of the VB legacy conversion methods have
backward compatibility baggage. I don''t recall the specifics, but it''s best
to make direct calls into the CLR so you know exactly what you''re getting,
when writing new code. When converting legacy VB6 code, that''s when you''d
use the VB versions, at least in early iterations of the conversion.

The best you can hope for, it seems to me, is that CInt() does nothing more
than call Convert.ToInt32(); at minimum, that''s an extra call. I''d just as
soon avoid that.

Another oft-overlooked issue is that when writing new code it''s better to
use AndAlso / OrElse rather than And/Or, so that you get rid of one of VB''s
most annoying features: lack of short-circuit evaluation. Again, you''d
stick with And / Or when trying to get a clean conversion of legacy VB6
code, or on those rare occasions when you actually don''t want short-circuit
evaluation.

--Bob

"rawCoder" <ra******@hotmail.com> wrote in message
news:eh*************@TK2MSFTNGP15.phx.gbl...


只想知道VB转换之间是否有任何速度差异如CInt,Clng,CStr,CDbl,CBool​​等关键词
.NETs Convert.To< .. >方法。

哪个更好用,为什么?

Thanx
rawCoder
Hi,

Just wanted to know if there is any speed difference between

VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc.
.NETs Convert.To<...> methods.

And which is better to be used and why ?

Thanx
rawCoder



Bob,
Bob,
我个人使用通用的.NET方法,如Convert.ToInt32()而不是CInt()等等。这使你的程序与其他.NET
语言更加一致,包括C#。


这有什么好处,在我的想法中你能比写得更好

直接用C

一些VB遗留转换方法具有向后兼容性的行李。
Personally I use the generic .NET methods like Convert.ToInt32() instead
of CInt(), etc. This makes your programs more congruent with other .NET
languages, including C#.
What is the advantage from this, in my idea can you than better write it
direct in C
Some of the VB legacy conversion methods have backward compatibility
baggage.




什么是VB遗留转换方法。 C#,C ++,J ++,JavaScript和Java以及来自C派生语言的东西都有很多遗留的C东西。 (在我看来,用什么

几乎没有什么问题)


Cor



What are VB legacy conversion methods. C#, C++, J++, JavaScript and Java and
what ever from C derived languages have a lot of legacy C stuff. (With what
in my opinion is almost nothing wrong by the way)

Cor


这篇关于VB转换关键字和.NET转换例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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