Object Lists Comparison - C #

2

I need to compare 2 lists of objects that have been filled via the database, according to classes below:

public class Ausente
{
    public ObjectId Id { get; set; }
    public Int32 RA { get; set; }
}

public class AlunoEstagio
{
    public ObjectId Id { get; set; }
    public Int32 RA { get; set; }
    public String ALUNO { get; set; }
    public Int32 PERIODO { get; set; }
    public String DISCIPLINA { get; set; }
    public char CONCEITO { get; set; }
}

List 1 will receive the Missing object, list 2 will receive the StudentSite object.

I would like to compare the 2 lists so that when there is an RA attribute of List 1 present in List 2, that the corresponding object of List 2 is added to a third list (List 3).

I have no idea how to make this comparison, could you help me?

    
asked by anonymous 31.10.2015 / 18:26

1 answer

0

If both types were the same, you could use Intersect , but since they are not , I think the code below does what you need:

var list3 = from l1 in list1
            join l2 in list2 on l1.RA equals l2.RA
            select new
            {
                l1,
                l2
            };

Where list1 and list2 are of type List<Ausente> and List<AlunoEstagio> respectively.

    
31.10.2015 / 19:04