var varEmployees = new[] { new {ID=1, Name="E1"}, new {ID=1, Name="E1"}, new {ID=2, Name="E2"}, }; var result = varEmployees.Distinct(); foreach (var employee in varEmployees) { MessageBox.Show(employee.Name); } //I get E1, E1, E2
1.) If you're storing your "Distinct()" sequence within the "result" variable then why are you enumerating through "varEmployees" instead of enumerating through "result"? 🤣🤣 2.) Even if you did enumerate through "result", you won't get distinct records because you haven't projected employees' "ID" and "Name" into a new anonymous type within your "Distinct()" operator.
Thank you sir. Video is Mind Blowing... :)
Really gr8 videos.... I will glad if you can upload video for unit testing...
cool, what if I only want either ID's, or only name, or a combination of different values to be distinct using Linq syntax?
Thanks Venkat! :)
Could some one please explain to me why did we use XOR operator to combine both HashCodes? I couldn't understand that.
to get int value unique for this combination of two properties.
Cool. I never knew that about anonymous types.
nice
Why such things have been made complicated.
var varEmployees = new[]
{
new {ID=1, Name="E1"},
new {ID=1, Name="E1"},
new {ID=2, Name="E2"},
};
var result = varEmployees.Distinct();
foreach (var employee in varEmployees)
{
MessageBox.Show(employee.Name);
}
//I get E1, E1, E2
1.) If you're storing your "Distinct()" sequence within the "result" variable then why are you enumerating through "varEmployees" instead of enumerating through "result"? 🤣🤣
2.) Even if you did enumerate through "result", you won't get distinct records because you haven't projected employees' "ID" and "Name" into a new anonymous type within your "Distinct()" operator.