PC Review


Reply
Thread Tools Rate Thread

Altering collection elements in place

 
 
Jeff Stewart
Guest
Posts: n/a
 
      10th Jul 2004
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).AddDays(-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.


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      10th Jul 2004
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.Visual.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


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      10th Jul 2004
* "Jeff Stewart" <(E-Mail Removed)> 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).AddDays(-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/>
 
Reply With Quote
 
Frank
Guest
Posts: n/a
 
      10th Jul 2004
Jeff,
I like the collections better than things like arrays. And as far as I know,
MS uses them for all their storage, like controlscollections 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" <(E-Mail Removed)> wrote in message
news:#Ch1#(E-Mail Removed)...
> 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.Visual.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
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      10th Jul 2004
* "Frank" <(E-Mail Removed)> scripsit:
> I like the collections better than things like arrays. And as far as I know,
> MS uses them for all their storage, like controlscollections 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.Collections' namespace.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      10th Jul 2004
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.Collections & System.Collections.Specialized instead of
the Micrososft.VisualBasic.Collection class. As Herfried suggests the
ArrayList (from System.Collections) 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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).AddDays(-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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Finding elements in a collection Chip Pearson Microsoft Excel Programming 1 11th Jan 2007 11:38 PM
Re: Finding elements in a collection paul.robinson@it-tallaght.ie Microsoft Excel Programming 0 11th Jan 2007 04:52 PM
accessing elements in a collection suspended@gmail.com Microsoft C# .NET 3 19th Jul 2006 03:38 PM
Arrays vs collection ? more than 100 elements =?Utf-8?B?dmlrcmFudGNh?= Microsoft Dot NET Framework 1 30th Sep 2004 09:34 PM
Bug: form.elements collection =?Utf-8?B?Z2xpc3Rhcg==?= Windows XP Internet Explorer 0 9th May 2004 04:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.