Hi,
Why is var excludes = users.Except(matches);
not excluding the matches
?
What is the proper way if I want the equality comparer to use only the ID
? Examples would be appreciated.
public class User
{
public int ID { get; set; }
public string Name { get; set; }
public override string ToString()
{
return ID.ToString() + ":" + Name;
}
}
private static void LinqTest2()
{
IEnumerable<User> users = new List<User>
{
new User {ID = 1, Name = "Jack"},
new User {ID = 2, Name = "Tom"},
new User {ID = 3, Name = "Jim"},
new User {ID = 4, Name = "Joe"},
new User {ID = 5, Name = "James"},
new User {ID = 6, Name = "Matt"},
new User {ID = 7, Name = "Jon"},
new User {ID = 8, Name = "Jill"}
}.OfType<User>();
IEnumerable<User> localList = new List<User>
{
new User {ID = 4, Name = "Joe"},
new User {ID = 5, Name = "James"}
}.OfType<User>();
//After creating the two list
var matches = from u in users
join lu in localList
on u.ID equals lu.ID
select lu;
Console.WriteLine("--------------MATCHES----------------");
foreach (var item in matches)
{
Console.WriteLine(item.ToString());
}
Console.WriteLine("--------------EXCLUDES----------------");
var excludes = users.Except(matches);
foreach (var item in excludes)
{
Console.WriteLine(item.ToString());
}
}