Selecting multiple filters based on the true/false conditions I wrote a method to select the filters (two or more) based on the true/false conditions. Here is the method I used for selecting the multiple filters:

    public T SetPropertyTypes&lt;T&gt;(bool residential, bool commercial) where T : IPage, new()
{

    // Residential Property Type Check logic
    if (residential &amp;&amp; (ElementIsNotActive(() =&gt; FindElement(By.CssSelector(propertyTypeResidentialCss))).Invoke(Driver)))
        ClickButton(() =&gt; FindElement(By.CssSelector(propertyTypeResidentialCss)), "Residential");
    else if (ElementIsActive(() =&gt; FindElement(By.CssSelector(propertyTypeResidentialCss))).Invoke(Driver))
        ClickButton(() =&gt; FindElement(By.CssSelector(propertyTypeResidentialCss)), "Residential");

    // Commercial Property Type Check logic
    if (commercial &amp;&amp; (ElementIsNotActive(() =&gt; FindElement(By.CssSelector(propertyTypeCommercialCss))).Invoke(Driver)))
        ClickButton(() =&gt; FindElement(By.CssSelector(propertyTypeCommercialCss)), "Commercial");
    else if (ElementIsActive(() =&gt; FindElement(By.CssSelector(propertyTypeCommercialCss))).Invoke(Driver))
        ClickButton(() =&gt; FindElement(By.CssSelector(propertyTypeCommercialCss)), "Commercial");
}


Later I found that the code is redundant and it could be better if I make it simpler and non-ambiguous. I'm new to C# and am not aware of many features. Is there any way to refactor this using any features of C#? I tried checking the variables using if-else-if but that's not working as intended.
Yes your code has a lot of redundancy.  It can be simplified down to this:

if (residential)
{
    ClickButton(() =&gt; FindElement(By.CssSelector(propertyTypeResidentialCss)), "Residential");
}
if (commercial)
{
    ClickButton(() =&gt; FindElement(By.CssSelector(propertyTypeCommercialCss)), "Commercial");
}