C# 确定三个字段中是否有一个包含关键字列表

C# 确定三个字段中是否有一个包含关键字列表,c#,string,list,contains,C#,String,List,Contains,假设我们有一个模型 public Foo { string Something {get;set;} string SomethingElse {get;set;} string AnotherThing {get;set;} } 确定这些字段是否包含列表中的任何字符串的最简洁方法是什么 var foo = new Foo { Something = "If Liverpool don't beat Fulham this evening I will cr

假设我们有一个模型

public Foo 
{
    string Something {get;set;}
    string SomethingElse {get;set;}
    string AnotherThing {get;set;}
}
确定这些字段是否包含
列表中的任何字符串的最简洁方法是什么

var foo = new Foo 
{
    Something = "If Liverpool don't beat Fulham this evening I will cry",
    SomethingElse = "I hope I have that TekPub membership for Xmas",
    AnotherThing = "I wish NCrunch was a bit cheaper"
};

var keywords = new List<string> { "Liverpool", "glosrob", "stackoverflow" };
var foo=新foo
{
Something=“如果利物浦今晚不击败富勒姆,我会哭”,
SomethingElse=“我希望我能成为TekPub的圣诞会员”,
另一件事=“我希望NCrunch能便宜一点”
};
var关键字=新列表{“利物浦”、“glosrob”、“stackoverflow”};
将传递包含“利物浦”一词的foo.Something

类似

new[] { foo.Something, foo.SomethingElse, foo.AnotherThing }.Any(s => keywords.Any(w => s.Contains(w)))
var entriesSet=newhashset(foo.Something.Split());
UnionWith(foo.SomethingElse.Split());
entriesSet.UnionWith(foo.AnotherThing.Split());
if(中心设置重叠(关键字)){
...
}

请记住用相关语言标记您的问题。我为您解决了这个问题,但我希望2k+代表用户第一次就知道如何正确使用它。
var entriesSet = new HashSet<string>(foo.Something.Split());
entriesSet.UnionWith(foo.SomethingElse.Split());
entriesSet.UnionWith(foo.AnotherThing.Split());

if (entriesSet.Overlaps(keywords)) {
    ...
}