I'm trying to remove strings from List by given command. The command is to remove all strings that starts or ends with given string.
List input = new List() {"Pesho", "Misho", "Stefan"};
string command = "Remove StartsWith P"; or "Remove EndsWith P"
I'm trying to do it with lambda. Smth like this:
input.RemoveAll(x =>
{
if (command[1] == "StartsWith")
x.StartsWith(command[2]);
else if (command[1] == "EndsWith")
x.EndsWith(command[2]);
});
The compiler says: Not all code paths return a value in lambda expression of type Predicate
I'm asking is it possible to do it inside one lambda, or I have to write it for both cases.