开发者

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

开发者 https://www.devze.com 2023-01-13 01:17 出处:网络
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\".

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

精彩评论

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

关注公众号