我已经研究了regex&sqlmatch与linq的关系,但似乎找不到适合我的情况的规则。我要创造的是…

//dataCollected[0] = { Name="joe", Url="http://my.home.site/" }
//dataCollected[N] = { Name="example", Url="http://german.home.site/" }

public bool hasParent(string test_url){
    var obj = dataCollected.Where(s => ( test_url.contains(s.Url)));
    return obj.Count() > 0;
}

bool  result  = hasParent("http://my.home.site/ShouldBeTrue"); //Finds http://my.home.site/

最佳答案

你快到了,应该是相反的方向。另外,使用linqAny。如果找到任何匹配项,则返回true:

public bool hasParent(string test_url)
{
    return dataCollected.Any(s => test_url.Contains(s.url));
}

09-26 23:57
查看更多