LINQ: …Where(x => x.Contains(string that start with “foo”))

前端 未结 5 985
南旧
南旧 2021-01-04 19:06

Given a collection of the following class:

public class Post
{
    ...
    public IList Tags { get; set; }
}

Is there an easy

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 19:33

    var tag = "foo";
    var postsWithFooTag = 
      posts.Where( p=> p.Tags.Any( t => t.StartsWith(tag)));
    

提交回复
热议问题