PC Review


Reply
Thread Tools Rate Thread

determine object's collection

 
 
Jure Bogataj
Guest
Posts: n/a
 
      19th Nov 2007
Hello!

This may be a silly question, but anyway:

If I have collection / list of objects:

public class MyCollection : List<MyObject>
{
}

public class MyObject
{
...
}

And then somewhere in the code I add object to the collection:
....
MyCollection col = new MyCollection()
MyObject obj = new MyObject()
col.Add(obj);

Is it possible now to determine which is obj's parent collection (sth like:
obj.?ParentCollection?) or must I manually track parent collections (e.g.
new MyObject(col) or sth like that). I know object can participate in more
than one collection at the same time (or not) so this may not be possible at
all?


Thanks in advance!

Best regards,
Jure


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      19th Nov 2007
On Nov 19, 11:23 am, "Jure Bogataj" <jure.boga...@mikrocop.com> wrote:

<snip>

> And then somewhere in the code I add object to the collection:
> ...
> MyCollection col = new MyCollection()
> MyObject obj = new MyObject()
> col.Add(obj);
>
> Is it possible now to determine which is obj's parent collection (sth like:
> obj.?ParentCollection?) or must I manually track parent collections (e.g.
> new MyObject(col) or sth like that). I know object can participate in more
> than one collection at the same time (or not) so this may not be possible at
> all?


You'd have to have specific support in MyObject for this - an object
doesn't have any inherent idea of whether it's part of another
collection or not.

Jon
 
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
Adding class object to collection repeats same object through collection? Erazmus Microsoft Excel Programming 2 17th Sep 2007 04:35 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
Determine if an item is in a Collection =?Utf-8?B?am1obWFpbmU=?= Microsoft VB .NET 3 19th Jul 2005 07:37 AM
determine number in a collection =?Utf-8?B?c21rMjM=?= Microsoft Access VBA Modules 4 29th Jun 2005 11:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:55 PM.