I am new in C#, I would like to write an extention method that I can execute on IList
and filter it by my tags.
I wrote such method
public static IList<string> FilterByTag(this IList<string> input, params string[] tags)
{
return input.Where(tmp => { <--- This line error
foreach (var tag in tags)
{
if (tmp.Contains(tag))
{
return true;
}
return false;
}
});
}
In that line (above), exactly here =>
I get a message that `Not all paths return a value in lambda...
What am I doing wrong?
UPDATE
Edited after Anu Viswan's response
public static IList<string> FilterByTag(this IList<string> input, params string[] tags)
{
return input.Where(tmp => {
bool result = true;
foreach (var tag in tags)
{
if (tmp.Contains(tag))
{
result = true;
}
result = false;
}
return result;
});
}