Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public List<carlistviewmodel> GetFilter(List<string> HondaCustomer, List<carlistviewmodel> CarList)
        {
            List<carlistviewmodel> List = new List<carlistviewmodel>();
            
                foreach (string Hcustomer in HondaCustomer)
                {
                    foreach (CarListViewModel detail in CarList)
                    {
                        if (detail.CustomerName == Hcustomer)
                        {
                            List.Add(detail);

                        }
                    }
                }
            

            return List;
        }


What I have tried:

C#
public List<carlistviewmodel> GetFilter(List<string> HondaCustomer, List<carlistviewmodel> CarList)
        {
            List<carlistviewmodel> List = new List<carlistviewmodel>();
            
                foreach (string Hcustomer in HondaCustomer)
                {
                    foreach (CarListViewModel detail in CarList)
                    {
                        if (detail.CustomerName == Hcustomer)
                        {
                            List.Add(detail);

                        }
                    }
                }
            

            return List;
        }
Posted
Updated 17-Nov-17 20:09pm
v2
Comments
BillWoodruff 17-Nov-17 18:07pm    
What happens now when you run your code: what errors; what unexpected result ? Your learning to analyze your code, to set breakpoints, etc., is critical for you to progress as a programmer.

1 solution

If I understand the question correctly I think you are looking for:
List<carlistviewmodel> List = CarList.Where(detail => HondaCustomer.Contains(detail.CustomerName)).toList();
 
Share this answer
 
Comments
BillWoodruff 17-Nov-17 18:04pm    
+5 solid solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900