Can we add LINQ where condition of method parameters

Below is my existing method using inside some condition

public List<MenuItem> getTopMenu(List<Role> Id)
{

 // here many lines code for checking id value
}

I am changing above method to check where condition inside method parameter like below but not working code

public List<MenuItem> getTopMenu(List<Role> Id.Where(r=>r.status=="Active"))
{

}

Error is coming i need to pass only active id inside method i can not write individually to every method.

Answer

Move the filter inside the method:

public List<MenuItem> getTopMenu(List<PersonRoleDTO> Id)
{
    Id = Id.Where(r=>r.status=="Active").ToList();
    // Whatever else
}

You cannot put statements as parameters to a method.

Leave a Reply

Your email address will not be published. Required fields are marked *