473,569 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Altering collection elements in place

Let's say I create a collection of DateTime objects like so:

Dim clxn_Times As Collection = New Collection()

Let's go on to say I add 3 elements to the collection. How do I pull off
the result represented by the following?

clxn_Times(0) = clxn_Times(0).A ddDays(-1)

I can't find a way to edit an item in place. But not knowing very much
about Visual Basic (or how to phrase this problem so I can find it in the
documentation), I can't figure out how to get a "reference" to an element so
that the element can be altered in place.

--
Jeff S.
Nov 20 '05 #1
5 1326
Hi Jeff,

For me a lot of stuff from the MicrosoftVisual .basic namespace is handy,
some I do not use and one I do not like. That is the the
Microsoft.Visua l.Basic collection.

It works so different from the rest of the dotNet stuff, I advice you to
have a look at the arraylist, a very handy class to make collections.

And when that does not fit you can have a look at hashtable, or sortedlist

I hope this helps?

Cor
Nov 20 '05 #2
Jeff,
I like the collections better than things like arrays. And as far as I know,
MS uses them for all their storage, like controlscollect ions and so on.
Edit in place? You store the reference to an object in a collection. So if
you 'take out' an object from the collection it's just a pointer. After
editing u don't have to put it back into the collection to save it.

Frank

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:#C******** ******@tk2msftn gp13.phx.gbl...
Hi Jeff,

For me a lot of stuff from the MicrosoftVisual .basic namespace is handy,
some I do not use and one I do not like. That is the the
Microsoft.Visua l.Basic collection.

It works so different from the rest of the dotNet stuff, I advice you to
have a look at the arraylist, a very handy class to make collections.

And when that does not fit you can have a look at hashtable, or sortedlist

I hope this helps?

Cor

Nov 20 '05 #3
* "Jeff Stewart" <ob******@hotma il.com> scripsit:
Let's say I create a collection of DateTime objects like so:

Dim clxn_Times As Collection = New Collection()

Let's go on to say I add 3 elements to the collection. How do I pull off
the result represented by the following?

clxn_Times(0) = clxn_Times(0).A ddDays(-1)

I can't find a way to edit an item in place. But not knowing very much
about Visual Basic (or how to phrase this problem so I can find it in the
documentation), I can't figure out how to get a "reference" to an element so
that the element can be altered in place.


You will have to remove and re-add the item (seem methods 'Remove' and
'Add' of the collection).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
* "Frank" <fr***@frank.co m> scripsit:
I like the collections better than things like arrays. And as far as I know,
MS uses them for all their storage, like controlscollect ions and so on.
Edit in place? You store the reference to an object in a collection. So if
you 'take out' an object from the collection it's just a pointer. After
editing u don't have to put it back into the collection to save it.


.... that's true for 'ArrayList' and most other collections in the
'System.Collect ions' namespace.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Jeff,
It appears that you have a collection of DateTime (Date) values. Correct?

System.DateTime is a value type, when you add a DateTime to a collection the
value will be boxed (copied to the heap) when you get the value from the
collection a copy of the boxed value will be made, when you use AddDays a
copy of the value will be made. In other words for DateTime values your code
is the way to do it, as your code is the way it works!

Reference Types (such as Control) exist on the Heap, when you add a Control
to a collection the reference will be copied to the collection, only a
single Control object will exist on the heap...

As Cor suggested. I would also recommend you look at & use the Collection
classes in System.Collecti ons & System.Collecti ons.Specialized instead of
the Micrososft.Visu alBasic.Collect ion class. As Herfried suggests the
ArrayList (from System.Collecti ons) will allow your code with casting,
because the ArrayList holds objects, your DateTime values will need to be
boxed going in (Add, Item set), and unboxed coming out (Item get, For Each)
of the ArrayList.

NOTE: In VS.NET 2005 (Whidbey) due out sometime in 2005 will support
Generics, you will be able to very easily make a strongly typed "ArrayList"
class, no boxing involved.

Hope this helps
Jay
"Jeff Stewart" <ob******@hotma il.com> wrote in message
news:46******** *************** *******@news.te ranews.com...
Let's say I create a collection of DateTime objects like so:

Dim clxn_Times As Collection = New Collection()

Let's go on to say I add 3 elements to the collection. How do I pull off
the result represented by the following?

clxn_Times(0) = clxn_Times(0).A ddDays(-1)

I can't find a way to edit an item in place. But not knowing very much
about Visual Basic (or how to phrase this problem so I can find it in the
documentation), I can't figure out how to get a "reference" to an element so that the element can be altered in place.

--
Jeff S.

Nov 20 '05 #6

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

Similar topics

8
2191
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in the process), I looked up the STL code. Erase certainly does not delete the memory associated with the element. However, it appears that the...
3
2182
by: Aaron | last post by:
I'm a newbie so please bear with me... I'm looking to parse XML into a Collection so that I can pass that collection around to functions to extract data from it easily. I'm hoping there is code already to parse std XML files into a Collection? All I've found is code where the XML structure is already known... I need to code to work no...
0
2385
by: emma middlebrook | last post by:
Tieing myself up in knots a bit here but am thinking about how to do the following two things ... 1. Unmodifiable ArrayList of elements of type T. If we are OK with checking at run-time we can just use ArrayList's static method ReadOnly to 'convert' the ArrayList into one that's unmodifiable. Calling anything that modifies the collections...
1
1981
by: Ana Lindt | last post by:
Hello, I remember reading in one of my books that it was possible to access some collection's elements with the dot (.) operator just like if they were properties. The problem is I don't remember what this kind of operation was called thus making it difficult to find documentation about it. I would apreciate if someone could just tell me...
10
6902
by: Kathy Burke | last post by:
HI. in asp.net app, I have an xmlDocument that I transform to the client html. Using xsl I create a few textboxes to capture user input. Each of these are related to <data> elements in the xmlDoc. I want to use the Forms collection to post the html form back to an asp.net page, and process each request.form object (textbox) via an xml...
5
1086
by: KenRoy | last post by:
Is there any way to do this without removing the object and then re-adding it with the updated property. Public Structure Blob Public f1 as String Public f2 as Boolean End Structure I then have a collection of Blobs defined and add 5 elements to the collection. I then want to be able to loop through the collection and
9
1670
by: jason.hau | last post by:
Is there any way to alter this? I am aware that it's read only. Essentially the problem is that I have a webcontrol that dynamically creates a textbox and a requiredfieldvalidator control with the validator validating the textbox. This worked fine in my test harness and works fine in my other projects using master page based pages when in IE...
9
3171
by: Generic Usenet Account | last post by:
I had a need to randomly select an element from an STL collection. It does not appear that this functionality is provided out-of-the-box with STL. Here is my crude implementation. I am using advance and distance in my approach. Is distance guaranteed to return an integral value? If not, can anyone suggest improvements: --Song /////...
158
7738
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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...
1
7673
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...
0
7970
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...
0
5219
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...
0
3653
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...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.