Call method by condition I apologize in advance for my English.
I have a user search method. It's parameters - login and strict. The last one determines, which method should have been used for search - Equals (strict is true) or Contains (strict is false). How should I implement it? I could do two different methods, but I think it would be code repeating.
    public async Task&lt;List&lt;UserFindInfoDTO&gt;&gt; FindUserByLoginAsync(string login, bool strict)
    {            
        var users = await context.Users
            .Where(u =&gt; u.Nickname.Equals(login)) // change on &quot;Contains&quot; if strict is false
            .Select(u =&gt; new UserFindInfoDTO
            {
                Status  = u.Status,
                Id = u.Id,
                MiniAvatar =  u.Image,
                Nickname = u.Nickname                    
            })
            .ToListAsync();
            ...
        return users;
    }
The lambda expression you pass to Where() is where you define the condition, so this is where it makes the most sense to put all the logic for this.
.Where(u =&gt; strict ? u.Nickname.Equals(login) : u.Nickname.Contains(login))

Or for higher performance you can conditionally pass a different lambda expression:
Func&lt;User,bool&gt; checker = strict
  ? (Func&lt;User,bool&gt;)((User u) =&gt; u.Nickname.Equals(login))
  : (Func&lt;User,bool&gt;)((User u) =&gt; u.Nickname.Contains(login));

...

.Where(checker)