473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Are collections not meant for modifying?

I have a hashtable full of objects. There seems to be no way to get an
object from the hashtable and modify it. Are collections or hashtables in
particular not meant for this kind of operation?
Nov 20 '05 #1
4 1064
* "Slonocode" <su**********@spamsux.net> scripsit:
I have a hashtable full of objects. There seems to be no way to get an
object from the hashtable and modify it. Are collections or hashtables in
particular not meant for this kind of operation?


You can simply modify it by changing the properties of the object stored
in the collection. Notice that you will have to cast to the type of the
object in order to access the properties:

\\\
DirectCast(foo, Goo).Baz = "..."
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2j*************@uni-berlin.de...
* "Slonocode" <su**********@spamsux.net> scripsit:
I have a hashtable full of objects. There seems to be no way to get an
object from the hashtable and modify it. Are collections or hashtables in particular not meant for this kind of operation?


You can simply modify it by changing the properties of the object stored
in the collection. Notice that you will have to cast to the type of the
object in order to access the properties:

\\\
DirectCast(foo, Goo).Baz = "..."
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Thank you that works. Would you be able to explain more how this is working
I'm not sure I understand it exactly? What am I casting from?

Nov 20 '05 #3
Slonocode,
There seems to be no way to get an
object from the hashtable and modify it. Use HashTable.Item to return a reference to one of the objects in the
collection, use mutable methods on this object to modify the object itself.

As Herfried suggested you may need to cast the object returned by
HashTable.Item to the type it actually is.
Are collections or hashtables in
particular not meant for this kind of operation? NO! collections & hashtables are entirely meant for this kind of operation!

Only time this doesn't really work is if you store value types (Integers,
Structures) in an ArrayList or HashTable, as the value type will be boxed,
and the boxed value will actually be stored.
Hope this helps
Jay

"Slonocode" <su**********@spamsux.net> wrote in message
news:2j*************@uni-berlin.de... I have a hashtable full of objects. There seems to be no way to get an
object from the hashtable and modify it. Are collections or hashtables in
particular not meant for this kind of operation?

Nov 20 '05 #4
* "Slonocode" <su**********@spamsux.net> scripsit:
You can simply modify it by changing the properties of the object stored
in the collection. Notice that you will have to cast to the type of the
object in order to access the properties:

\\\
DirectCast(foo, Goo).Baz = "..."
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Thank you that works. Would you be able to explain more how this is working
I'm not sure I understand it exactly? What am I casting from?


You are casting from 'Object', because the collection will hold objects
of any type that derives from 'Object'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

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

Similar topics

8
by: Arnaud Debaene | last post by:
Hello all, One area where the .Net framework 1.1 is really poor is Collections : We've got very few choice concerning the containers and their characteristics (for example, ArrayList, Queue and...
4
by: gmccallum | last post by:
This whole dispose topic confuses me regarding managed and unmanaged resources. I think that it was easier when you just cleaned up every object, which brings me to my problem. I have some...
7
by: rodchar | last post by:
hey all, i was checking out time tracker on asp.net one of the starter kit projects. i was wondering why the users datagrid gets loaded the way does. first it pulls all the users in from a...
6
by: mumrah | last post by:
When getting different elements out of an array in JS, i know array.item(0) and array both return the 0th element. My question, will this work in any instance?
4
by: Chris S. | last post by:
Am I correct in thinking that C#/.NET 2.0 removes the need for a collection for each business object you have, and allows you to create just one collection? Or is this just the equivalent of...
14
by: Jerad Rose | last post by:
I'm relatively new to C# and polymorphism, so what I'm trying to accomplish may not be possible, or there may be a totally different approach that I should be taking. I have a base class...
5
by: Droopy | last post by:
Hi, 1) Is it worth to replace all HashTable and ArrayList (framework 1.1) usage by Dictionary and List (framework 2.0) ? I suppose the answer would be yes as the 2.0 collections are type safe...
28
by: walterbyrd | last post by:
Python seems to have a log of ways to do collections of arbitrary objects: lists, tuples, dictionaries. But what if I want a collection of non-arbitrary objects? A list of records, or something...
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.