Filtering a list based on a value Based on dropdown value and search text I need to filter a list and return.

Method 1

if (selectedValue == 1 &amp;&amp; searchTerm.Length == 0)
return users;

if (selectedValue == 1 &amp;&amp; searchTerm.Length &gt; 0)
return users.Where(user=&gt;user.Name == searchTerm).ToList();

if (selectedValue == 2 &amp;&amp; searchTerm.Length &gt; 0)
return users.Where(user=&gt;(user.Name == searchTerm &amp;&amp; user.Street == "StreetA")).ToList();

if (selectedValue == 2 &amp;&amp; searchTerm.Length == 0)
return users.Where(user=&gt;user.Street == "StreetA").ToList();

if (selectedValue == 3 &amp;&amp; searchTerm.Length &gt; 0)
return users.Where(user=&gt;(user.Name == searchTerm &amp;&amp; user.Street == "StreetB")).ToList();

if (selectedValue == 3 &amp;&amp; searchTerm.Length == 0)
return users.Where(user=&gt;user.Street == "StreetB").ToList();


Method 2

if(searchTerm.Length &gt; 0)
{
    if (selectedValue == 1)
    return users.Where(user=&gt;user.Name == searchTerm).ToList();

    if (selectedValue == 2)
    return users.Where(user=&gt;(user.Name == searchTerm &amp;&amp; user.Street == "StreetA")).ToList();

    if (selectedValue == 3)
    return users.Where(user=&gt;(user.Name == searchTerm &amp;&amp; user.Street == "StreetB")).ToList();
}
else
{
    if (selectedValue == 1)
    return users;

    if (selectedValue == 2)
    return users.Where(user=&gt;user.Street == "StreetA").ToList();

    if (selectedValue == 3)
    return users.Where(user=&gt;user.Street == "StreetB").ToList();
}


I am not convenienced with above logics so please help improve this.
users.Where(user =&gt; cond &amp;&amp; cond2) is equivalent to users.Where(user =&gt; cond).Where(user =&gt; cond2)

So you can do the following:

IEnumerable&lt;User&gt; resultStream = users;

if(searchTerm.Length &gt; 0)
    resultStream = resultStream.Where(user.Name == searchTerm);

switch(selectedValue){
    case 1: 
        return resultStream.ToList();
    case 2:
        return resultStream.Where(user=&gt;user.Street == "StreetA").ToList();
    case 3:
        return resultStream.Where(user=&gt;user.Street == "StreetB").ToList();
}