Re: iterating over collection
Peter Osucha <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Ahhh, for some reason I continue to forget about that 'object' type. Thanks for this suggestion, Adrian. I'll play around with it a bit. Peter > -----Original Message----- > From: Discussion relating to the specifics of the C# and > Managed C++ languages [mailto:[email protected]] > On Behalf Of Adrian Martin > Sent: Monday, September 11, 2006 12:08 PM > To: [email protected] > Subject: Re: [DOTNET-CX] iterating over collection > > Opinions expressed in this email are those of the writer > and not the company. E-mail traffic is monitored within > Johnston Press and messages may be viewed. This e-mail and > any files with it are solely for the use of the addressee(s). > If you are not the intended recipient, you have received > this e-mail in error. Please delete it or return it to the > sender or notify us by email at [email protected] > > > Something like this should do - I think! > > static BaseObject FindObject(string mn, Dictionary<object, BaseObject> > c) > { > foreach (BaseObject bo in c.Values) > { > if (bo.MagicNumber == mn) > return bo; > } > > return null; > } > > -----Original Message----- > From: Discussion relating to the specifics of the C# and > Managed C++ languages [mailto:[email protected]] > On Behalf Of Peter Osucha > Sent: Monday 11 September 2006 15:44 > To: [email protected] > Subject: iterating over collection > > I have an abstract base object. > > I have several classes that are derived from the base object. > > I have several collection classes (one for each of the > derived classes) that internally use Dictionary<> objects - > but of course the generic collections use derived objects > even though all the derived objects are derived from the base object. > > I have several (one for each collection class) methods into > which I pass a collection class instance and which then look > for a specific object in the collection based on a property > that comes from the base object. > > Is there a way (I can't figure one out and don't know if it's > possible since the collection classes are all of specific > object types) to somehow have one method into which I could > pass any of the collection classes (since the are all based > on the Dictionary<> object though with different generic > objects even though all based on the abstract base > object) and then somehow loop over them after casting to the > base object type? > > It seems there *ought* to be a way even if I have to do some > minor rework on the derived objects or the collection objects. > > I hope this made some sense. > > Peter =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com