Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要通过与'比较来筛选“dataBefore”的数据;dataAfter';_C# - Fatal编程技术网

C# 需要通过与'比较来筛选“dataBefore”的数据;dataAfter';

C# 需要通过与'比较来筛选“dataBefore”的数据;dataAfter';,c#,C#,我有两个列表,需要在dataAfter列表中筛选Name和SectionId不匹配的dataBefore中的数据 var dataBefore = new List<School> { new School { Name = "N1", SectionId = null }, new School { Name = "N2", SectionId = new Guid("

我有两个列表,需要在
dataAfter
列表中筛选
Name
SectionId
不匹配的
dataBefore
中的数据

var dataBefore = new List<School>
        {
            new School { Name = "N1", SectionId = null },
            new School { Name = "N2", SectionId = new Guid("6aba7a38-8e61-472d-b4ce-b9fc2011af3f") },
            new School { Name = "N3", SectionId = null },
            new School { Name = "N4", SectionId = new Guid("ca663d45-04b8-4c80-96b6-c3760352a6ac") }
        };

        var dataAfter = new List<School>
        {
            new School { Name = "N1", SectionId = new Guid("5be0fc99-4826-4fbf-a190-b930af730b93") },
            new School { Name = "N3", SectionId = null },
            new School { Name = "N4", SectionId = null }
        };
下面的查询给出了完全相反的结果(仅
N3
),如何获得高于预期的结果

 var x = dataBefore.Where(y => dataAfter.Any(z => z.Name == y.Name && z.SectionId == y.SectionId)).ToList();
如果Any()返回false,则可以得到结果

 var x = dataBefore.Where(y => dataAfter.Any(z => z.Name == y.Name && z.SectionId == y.SectionId)).ToList();
var x = dataBefore.Where(y => !dataAfter.Any(z => z.Name == y.Name && z.SectionId == y.SectionId)).ToList();