I am wondering how can I achieve this?
I want to get only distinct names from a collection of objects
MyObject a = new Object();
a.Name = \'One\';
a.
You can implement your class so the linq distinct operator does not use the default equality comparer.
class YourClass:IEquatable
{
... Your implementation details. ...
public bool Equals(YourClass other)
{
if (Object.Equals(this, other))
{
return true;
}
else
{
if(Name == other.Name && Value == other.Value)
{
return true;
}
else
{
return false;
}
}
}
public override int GetHashCode()
{
return Name.GetHashCode() ^ Value.GetHashCode();
}
}