开发者

Finding items that corresponds to other items in the same collection using LINQ

I'm trying to wrap my head around this in LINQPAD and keep failing. Basically I need the entries that have a corresponding entry ending with "_SCHEMA".

So from the list below, I need "Dumbo" entry only

void Main()开发者_如何学Python
{
 var users = new List<User> {new User{Name="Dummy"}, new User{Name="Dumbo"}, 
new User{Name="Dunno"}, new User{Name="Dumbo_SCHEMA"}};

}

class User
{
  public string Name{get;set;}
}

Any thoughts are welcome.


Like this?

from user in users
    where users.Any(inner => inner.Name == user.Name + "_SCHEMA")
    select user

Edit: Beware of performance issues on too large sets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜