473,653 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using arraylist

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.?

Feb 17 '07 #1
28 1860
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*******@yaho o.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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.?
Feb 17 '07 #2
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*******@yaho o.comschreef in bericht
news:11******** **************@ q2g2000cwa.goog legroups.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.?

Feb 17 '07 #3
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
Feb 17 '07 #4

Hello
If you use framework 2.0, you can use a generic list instead of the
ArrayList, then you don't need the cast.
Before you misinterpreted this as "faster" by documentation yes however
in practice casting is faster

regards

michel
"Göran Andersson" <gu***@guffa.co mschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
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

Feb 17 '07 #5
Could you write that in a sentence that makes sense?

Did I misinterpret anything? Before or after what? What documentation?
What is it that casting is faster than?

Michel Posseth [MCP] wrote:
Hello
>If you use framework 2.0, you can use a generic list instead of the
ArrayList, then you don't need the cast.

Before you misinterpreted this as "faster" by documentation yes however
in practice casting is faster

regards

michel
"Göran Andersson" <gu***@guffa.co mschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>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


--
Göran Andersson
_____
http://www.guffa.com
Feb 17 '07 #6
On Feb 17, 9:49 am, Göran Andersson <g...@guffa.com wrote:
Could you write that in a sentence that makes sense?

Did I misinterpret anything? Before or after what? What documentation?
What is it that casting is faster than?

Michel Posseth [MCP] wrote:
Hello
If you use framework 2.0, you can use a generic list instead of the
ArrayList, then you don't need the cast.
Before you misinterpreted this as "faster" by documentation yes however
in practice casting is faster
regards
michel
"Göran Andersson" <g...@guffa.com schreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
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

--
Göran Andersson
_____http://www.guffa.com

I can't find an example of syntax for writing an arraylist as a
generic list. Can I please have an example?

Feb 17 '07 #7
wanwan,

Instead of this:

Dim myList As New ArrayList

do this:

Dim myList As New List (Of myClass)

Kerry Moorman
"wanwan" wrote:
On Feb 17, 9:49 am, Göran Andersson <g...@guffa.com wrote:
Could you write that in a sentence that makes sense?

Did I misinterpret anything? Before or after what? What documentation?
What is it that casting is faster than?

Michel Posseth [MCP] wrote:
Hello
>If you use framework 2.0, you can use a generic list instead of the
>ArrayList, then you don't need the cast.
Before you misinterpreted this as "faster" by documentation yes however
in practice casting is faster
regards
michel
"Göran Andersson" <g...@guffa.com schreef in bericht
>news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>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
--
Göran Andersson
_____http://www.guffa.com


I can't find an example of syntax for writing an arraylist as a
generic list. Can I please have an example?

Feb 17 '07 #8
Personally I'd use DirectCast but Stephany has given the best advice.
Rather than wonder stuff and rather than reading unsubstantiated opinions
from strangers who speculate on everything... do us a favor and run a short
test. Construct loops using CType and DirectCast long enough to produce
meaningful results and post a short version of the code and the times you
generate here.

First everybody gets a little smarter for the exercise, second we have facts
rather than opinions and third each of us can test the code on our own
machines if we feel like confirming the results. Basing our opinions on
facts isn't a bad thing. :-)

"wanwan" <er*******@yaho o.comwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.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.?

Feb 17 '07 #9
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.?
Maybe you want to check on a somewhat authoritative opinion:

DirectCast revealed
<http://www.panopticonc entral.net/archive/2003/07/10/149.aspx>

HTH.

Regards,

Branco.

Feb 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1152
by: Mike Grasso | last post by:
I've seen a few messages on this, but no responses. Here's what I found out PROBLEM: How do you use ArrayList.Synchronized to create thread-safe objects derived from ArrayList public class MyList : ArrayList { }
0
6267
by: si | last post by:
I'm very new to using C# in an ASP.NET application, and am used to using the ADO GetRows() method to quickly dump data into a multidimensional array in classic ASP. I am trying to work through using the ArrayList class in ASP.NET to perform a similar role, but am having difficulty in understanding and knowing how to access the data once it has been placed in an ArrayList.
5
19892
by: zfeld | last post by:
How do I cast an object to its proper class at runtime given its System.Type I have code that looks like this: MyObject class has subclasses of MySubObjectA & MySubObjectB: MyObject obja = new MySubObjectA (); MyObject objb = new MySubObjectB (); ArrayList list = new ArrayList();
7
20763
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex properties, nothing happens.... The default blank value in the ComboBox is always selected. My code is: ...
1
2382
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I then check some boxes and hit the submit button. I can't seem to get the value that is selected on the RadioButton List. I don't want to use the EditTemplate thing I just want to click on the radiobutton and submit the form. I also don't want to do...
1
6414
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ? I'm posting my code below. The problem is that if i click on "AdjustThisAd" button, it opens...
16
1903
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I can get this using: dim b as string b = DirectCast(myarraylist(0),myclass).myproperty However, I want to use an object to define the type "MyClass" like: dim C as type = type.GetType(myarraylist(0))
0
1672
by: Grant Wickman | last post by:
Our team has just fixed a really nasty problem that appears to be caused by an obscure bug in the sort method of Arraylist and daisy-chained webservice stubs. We've fixed the bug so I'll not investigate any further but there was nothing about it when googling the newsgroups so I am posting a note in case it helps somebody else out. The problem was in a system with a web front end calling through to a chain of 3 webservices i.e.
0
2558
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation link (1,2,3 so on). The code can be found in SubscriptionCart.aspx.cs. Default.aspx ------------
0
3128
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the url,first it will ask for authentication.After giving username and password,the authentication will be confirmed and if the site has access right as allow,the website will open else a page will be displayed.There we can send request mail to the...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.