使用arraylist [英] using arraylist
问题描述
我写了一个类,并将此类中的对象添加到
arraylist中。当我从arraylist中检索对象时,我是否应该使用ctype或者直播将它们强制转换回原来的类。?
假设CType和DirectCast都适用于你的班级,那么最好的做法是测量两者的相对性能并使用
给出了最好的结果。
" wanwan" <呃******* @ yahoo.com写了留言
新闻:11 ********************** @ q2g2000cwa.googlegro ups.com ...
>我写了一个类,并将此类中的对象添加到
arraylist中。当我从arraylist中检索对象时,我是否应该使用ctype或者直播将它们强制转换回原始类。?
< blockquote> Eric
DirectCast意味着直接投射而不进行测试如果可能的话
Ctyps意味着如果需要转换并转换为不需要。
所以可能只有一个不可测量的更快的行为
直接演员
Cor
wanwan < er ******* @ yahoo.comschreef in bericht
news:11 ********************** @ q2g2000cwa.googlegro ups.com ...
>我写了一个类,并将此类中的对象添加到
arraylist中。当我从arraylist中检索对象时,我是否应该使用ctype或者直播将它们强制转换回原来的类。?
wanwan写道:
我写了一个类,并将此类中的对象添加到
arraylist中。当我从arraylist中检索对象时,我是否应该使用ctype或者直播将它们强制转换回原来的类。?
As你想要转换引用,而不是隐藏对象,你应该使用
DirectCast。
如果你使用框架2.0,你可以使用通用列表代替
ArrayList,那么你不需要演员。
-
G?ran Andersson
_____
http://www.guffa.com
I wrote a class and have objects from this class added to an
arraylist. When I retrieve the objects from the arraylist, should I
use ctype or directcast to cast them back to the original class.?
Assuming that both CType and DirectCast work for your class, then the best
thing to do is measure the relative performance of both and use the one that
gives the best results.
"wanwan" <er*******@yahoo.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...>I wrote a class and have objects from this class added to an
arraylist. When I retrieve the objects from the arraylist, should I
use ctype or directcast to cast them back to the original class.?
Eric
DirectCast means cast direct without testing if that is possibel
Ctyps means convert if needed and cast as not needed.
So there will probably only an not measurable quicker behaviour for the
Direct Cast
Cor
"wanwan" <er*******@yahoo.comschreef in bericht
news:11**********************@q2g2000cwa.googlegro ups.com...>I wrote a class and have objects from this class added to an
arraylist. When I retrieve the objects from the arraylist, should I
use ctype or directcast to cast them back to the original class.?
wanwan wrote:I wrote a class and have objects from this class added to an
arraylist. When I retrieve the objects from the arraylist, should I
use ctype or directcast to cast them back to the original class.?
As you want to cast the reference, not covert the object, you should use
DirectCast.
If you use framework 2.0, you can use a generic list instead of the
ArrayList, then you don''t need the cast.
--
G?ran Andersson
_____
http://www.guffa.com
这篇关于使用arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!