简体   繁体   English

比较C#中的两个字符串列表

[英]comparing two list of strings in C#

There are Candidate and Job entities: 有候选人和工作实体:

public class Candidate
{
    public int CandidateId { get; set; }
    public string Name { get; set; }
    public string SkillTags { get; set; }

    public List<string> skillTagsList
    {
        get
        {               
            return Array.ConvertAll(SkillTags.Split(','), p => p.Trim()).ToList();
        }
    }
}

public class Job
{
    public int JobId { get; set; }
    public string Name { get; set; }
    public string Company { get; set; }
    public string Skills { get; set; }

    public List<string> skillsList
    {
        get
        {
            return Array.ConvertAll(Skills.Split(','), p => p.Trim()).ToList();
        }
    }
}

For each job, I want to get the candidates with most matching skills. 对于每项工作,我都希望获得具有最匹配技能的候选人。 This LINQ query returns an error. 此LINQ查询返回错误。 is there a better LINQ query to get the results? 是否有更好的LINQ查询来获取结果?

List<Candidate> candidates = repository.GetCandidates().Result;
List<Job> jobs = repository.GetJobs().Result;
List<Candidate> JobCandidates = null;
jobs.ForEach(j =>
{
    JobCandidates = candidates.Where(c => c.skillTagsList.Any(st => j.skillsList.Contains(st.ToLower())));
}

For each job project ( .Select ) a new object containing the job and the candidate with the top number of matching skills ( OrderDescendingBy the number of intersections): 对于每个工作项目( .Select ),一个新对象包含该工作和具有最高匹配技能数( OrderDescendingBy相交数)的候选人:

var result = jobs.Select(j => new {
    Job = j,
    Candidate = candidates.OrderByDescending(c => c.skillTagsList.Intersect(j.skillsList).Count())
                          .First()
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM