我有一个List<Class1>
和List<Class2>
,我想从List<Class1>
中存在项目ID的List<Class2>
中获取所有项目,反之,则从List<Class1>
中获得所有项目项目的ID 不存在于List<Class2>
中。
public class Class1
{
public int Id { get; set; }
public string AnotherId { get; set; }
public decimal Price { get; set; }
}
public class Class2
{
public int Id { get; set; }
public int AnotherId { get; set; }
public string Message { get; set; }
}
我用Contains
尝试了几种解决方案,但找不到正确的方法。
您可以尝试这样的事情:
尝试这样的事情:
有几种方法,最简单的是System.Linq
方法Where
,All
和Any
: