C# iterate on class own elements

Total Post:128

Points:898
C# 
C#
 1322  View(s)
Ratings:
Rate this:

I have created a class which inherits from List: Now I want to iterate the elements of the class in the class itself and return the object if it satisfies certain criteria

protected class myList : List<Object> 
{
    getElement(string name)
    {
        ??? LOOP AND IF CONDITION ???
         return element;
    }
}

Can you help? Thanks

  1. Post:412

    Points:2888
    Re: C# iterate on class own elements

    Hi Ashish, 

    try this:

        public Object GetElement(string name)
        {
            Object element = null;
            foreach (var item in this)
            {
                if (item.ToString() == name)
                {
                    element = item;
                    break;
                }
            }
            return element;
        }

      Modified On Apr-04-2018 05:50:50 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!