为什么我收到错误“并非所有路径都返回值”?

Ale*_*nko -2 c#

我是 C# 新手,我想编写一个扩展方法,我可以在IList它上面执行并通过我的标签对其进行过滤。

我写了这样的方法

        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;
                }
            });
        }
Run Code Online (Sandbox Code Playgroud)

在该行(上方)中,正是在这里,=>我收到一条消息,“并非所有路径都返回 lambda 中的值...

我究竟做错了什么?

更新

在 Anu Viswan 的回应后编辑

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;
                });
            }
Run Code Online (Sandbox Code Playgroud)

Jaw*_*wad 5

你可以简单地使用 Linq

input.Where(tmp => tags.Any(tag => tmp.Contains(tag));
Run Code Online (Sandbox Code Playgroud)