CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
class Aluno {
public int Id {get;set;}
public string Nome {get;set;}
}
public static void Main()
{
List<Aluno> aluno01 = new List<Aluno>();
aluno01.Add(new Aluno { Id = 1, Nome = "1111" });
aluno01.Add(new Aluno { Id = 2, Nome = "2222" });
aluno01.Add(new Aluno { Id = 2, Nome = "5555" });
List<Aluno> aluno02 = new List<Aluno>();
aluno02.Add(new Aluno { Id = 1, Nome = "1111" });
aluno02.Add(new Aluno { Id = 2, Nome = "2222" });
aluno02.Add(new Aluno { Id = 2, Nome = "3333" });
aluno02.Add(new Aluno { Id = 2, Nome = "4444" });
var intersect = aluno01.Where(a => !aluno02.Select(b => b.Nome).Contains(a.Nome)).ToList();
for (int i = 0; i < intersect.Count(); i++)
{
Console.Write("Id:" + intersect[i].Id + "- Nome:" + intersect[i].Nome);
}
}
}