Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2007, 02:09 PM
Registered User
 
Join Date: Feb 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exist Finder classes to find elements into List?

So, I would like me know if exist any library or utility in order to find a group of elements added into ArrayList.

    Mmm, Now I find elements as follow:

       System.Collections.ArrayList result = new System.Collections.ArrayList();
            foreach (Element element in elements)
            {
                //Criterium-->
                if (element.Code == "X")
                {
                    result.Add(client);
                }
            }
            return result;

I would like me to use as a Finder class or something.

Can you help me please?

 
Old February 11th, 2007, 06:05 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Collection is a collection.
Your Data Structure (element with a time field) can add to the capabilties of the Collection.
Maybe you can create your own class, with some other features, of having a sub collecton, that I dont know.
Nor do I know the correct answer to this question.

I hope this is of help.
 
Old February 12th, 2007, 01:02 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Usually this is done with a custom collection. Extend the CollectionBase class to create your own collection type that as custom finder methods. The methods can be implemented as standard methods or as indexers. Here's how I would implement it:
Code:
    public class MyClass
    {
    }
    public class MyClassCollection : System.Collections.CollectionBase
    {
        public int Add(MyClass item)
        {
            return this.InnerList.Add(item);
        }
        public MyClass FindItem(string test){
            for (int i = 0; i < this.InnerList.Count; i++)
            {
                if(this[i].<property> == <test condition>){
                    return this[i];
                }
            }
        }
        public MyClass this[int index]
        {
            get { return (MyClass)this.InnerList[index]; }
        }
        public MyClass this[string test]
        {
            get { return FindItem(test); }
        }
    }
-Peter
 
Old February 14th, 2007, 11:50 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, I would like me know if exist any library or utility in order to find a group of elements added into ArrayList.

    Mmm, Now I find elements as follow:

       System.Collections.ArrayList result = new System.Collections.ArrayList();
            foreach (Element element in elements)
            {
                //Criterium-->
                if (element.Code == "X") 'code seems to me maybe it should be examples not "X" != X <> "X" whatever
                {
                    result.Add(client);
                }
            }
            return result;

Please Excuse me but the code maybe adjusted for whatever you are doing by changing not equal X, I did not notice this before.
I hope I see this correctly its tough replying to something I can not see.
 
Old February 19th, 2007, 01:31 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is no built in method for finding items by an arbitrary test. You have to build methods that do it because you have to define the actual test you will perform to determine which items of the list match your test value. This will always involve iterating thru the list of items and testing each one, then doing whatever you need to with them (whether it's adding them to another list or returning a flag indicating that did or did not find the desired item).

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL file can't find elements in XML data? Mateo1041 XSLT 2 September 18th, 2008 09:37 AM
order elements of list box Vince_421 Access VBA 2 April 28th, 2007 11:18 AM
Defining Classes for Elements; page 734 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 July 23rd, 2006 04:10 AM
Find records that don't exist harg7769 MySQL 0 April 28th, 2005 10:44 AM
Find records that don't exist harg7769 Access 1 April 20th, 2005 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.