在具有lambda的课程列表中查找课程列表 [英] Find list of class in list of class with lambda

查看:45
本文介绍了在具有lambda的课程列表中查找课程列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个同步类

internal sealed class Synchronize
{
    internal _File File { get; set; } = new _File();
    internal _Log Log { get; set; } = new _Log();

    internal sealed class _File
    {
        internal string Folder { get; set; }
        internal string Name { get; set; }
        internal string Extention { get; set; }
        internal string Create_Date_Time { get; set; }
        internal long Size { get; set; }
        internal int RecordCount { get; set; }
    }

    internal sealed class _Log
    {
        internal string Folder { get; set; }
        internal string Name { get; set; }
        internal string Extention { get; set; }
        internal string CreateDateTime { get; set; }
    }
}

我还有另一个班级迁移

internal sealed class Migrate
{
    internal string FileFolder { get; set; }
    internal string FileName { get; set; }
    internal int RecordCount { get; set; }
    internal bool CanMigrate { get; set; } = false;
}

我有

List<Synchronize> synchronize

List<Migrate> migrate

同步"具有100多个列表项,而迁移"具有1+多个列表项.

synchronize has 100+ list items, but migrate has 1+ list items.

有没有一种方法可以使用lambda表达式通过搜索migration来同步查找存在于Migration中的所有项目.FileFolder&&migration.FileName&&migration.RecordCount?

Is there a way using a lambda expression to find all item in synchronize that exist in migrate by means of searching for migrate.FileFolder && migrate.FileName && migrate.RecordCount?

我知道如何通过迭代迁移的方式在同步上进行lambda搜索,但是我试图避免迭代并尝试学习更多的lambda,当您开始掌握它时,它是如此的酷:)

I know how to do a lambda search on synchronize by way of iterating though migrate, but I'm trying to avoid the iteration and trying to learn more lambda, it is so cool when you begin to grasp it :)

推荐答案

可以使用

var results = synchronize.Where(s => migrate.Any(m => /* compare here */));

但我可能会使用联接:

var results = from s in synchronize
              join m in migrate
              on new { s.File.Folder, s.File.Name, s.File.RecordCount }
              equals new { Folder = m.FileFolder, Name = m.FileName, m.RecordCount }
              select s;

或使用lambda语法:

Or in lambda syntax:

var results = synchronize.Join(migrate,
    s => new { s.File.Folder, s.File.Name, s.File.RecordCount },
    m => new { Folder = m.FileFolder, Name = m.FileName, m.RecordCount },
    (m, s) => s);

这篇关于在具有lambda的课程列表中查找课程列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆