It is not easy to post a working example however I have constructed some
simple pseudo code to demonstrate. The application
is written in vb however to attempt to write the example in vb would make it
unclear.
class MyList: Inherits Collections.Specialized.ListDictionary
{
bool LoadListFromFile(string _StrFileName as string){}
bool SaveListToFile(string _StrFileName as string){}
bool AddItemToList(string _StrItem as string){}
}
class MyForm
{
// I have declared a list somewhere else and I am simply assigning a
ref to the class here
// the list has already been initialised and loaded
MyList _ListClass= AnotherListClass;
//enumerate object to display items
object _MyObject;
// _ListClass.count=3 There are items in the list
for each _MyObject in _ListClass
// the items are added to the list no problem
list.items.add _MyObject
next
// now after the loop the object appears to go out of scope
// and the dispose method is called by .Net. I could understand this if
the object was declared here
// however the object is declared in somewere else. I do not loose the
ref to the MyList class
// it is only the base class that is disposed of. I have seen the same
behaviour with other similar implementations
// I think the problem is something obvious however just cannot see it.
// _ListClass.count=0 there are now no items
}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Alex <al*********@hotmail.co.uk> wrote: I have a class that has inheritted a collectionbase class
The class works fine generally, I can add items to the collection
however whenever I execute a For Each loop, the dispose event is called and then
inherited collection disapears. (The same problem occurs regardless of
which collection type I inherit)
I cannot figure this out as I still have a ref to the object that
inherits the collection. I think it is something like the collection object is
not referenced to the class that inherits it however I cannot see how to fix
it.
Any ideas on this would be appreciated
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too