I would just like to start by saying hi. I am a new user here. I have read the forms for a long time but have never joined. I am new to C# but I will try to answer any questions I can on the form.

My question is, is it possible to have a multi item .FindAll? I am trying to find all inspection keys that are of a certain type.

List<Inspections> InspectionsType = new List<Inspections>();
            List<Inspections> InspectionKey = new List<Inspections>();


          InspectionsType = myInspections.FindAll(delegate(Inspection insp) { return insp.Type == ProjectInspectionType.Basic; });

          InspectionKey = InspectionsType.FindAll(delegate(Inspection insp) { return insp.InspectionKey == myInspection.Key; });In my code above InspectionKey now

with my code above InspectionKey now has all inspection keys that are type Basic. I would like to do this with one findall.

InspectionsType = myInspections.FindAll(delegate(Inspection insp) { return insp.Type == 
ProjectInspectionType.Basic && insp.InspectionKey == myInspection.Key; });

something like that.


Thank you in advance for any help.

Your preferred code should work as intended, have you tried it? In a constructed example on my end, it works fine. I've included a lambda version and a delegate version to match your own method.

static void Main(string[] args)
        {
            List<Inspection> inspections = new List<Inspection>()
            {
                new Inspection("Basic","A"),
                new Inspection("Basic","A"),
                new Inspection("Basic","B"),
                new Inspection("Basic","B"),
                new Inspection("Basic","C"),
                new Inspection("Basic","C"),
                new Inspection("Enhanced","A"),
                new Inspection("Enhanced","B"),
                new Inspection("Enhanced","C"),
                new Inspection("Enhanced","D"),
            };

            var matches = inspections.FindAll(insp => insp.InspectionType == "Basic" && insp.InspectionKey == "A");
            var matches2 = inspections.FindAll(delegate(Inspection insp) { return insp.InspectionType == "Basic" && insp.InspectionKey == "A"; });

            Console.WriteLine(matches.Count); // writes 2
            Console.WriteLine(matches2.Count); // writes 2
            Console.Read();
        }
    }

    class Inspection
    {
        public Inspection(string type, string key)
        {
            this.InspectionType = type;
            this.InspectionKey = key;
        }

        public string InspectionType { get; set; }
        public string InspectionKey { get; set; }
    }

Thank you for your reply, I did not have a computer to try this out yesterday, I did work when I tried it today.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.