Tag: iequalitycomparer

IEqualityComparer <T>使用ReferenceEquals

有没有使用ReferenceEquals的默认IEqualityComparer<T>实现? EqualityComparer<T>.Default使用ObjectComparer,它使用object.Equals() 。 在我的情况下,对象已经实现了IEquatable<T> ,我只需要忽略和比较对象的引用。

如何使用IEqualityComparer

我的数据库中有一些相同的号码。 我想让所有这些都不重复。 然后我创build一个比较类来完成这个工作,但是函数的执行会使得函数有一个很大的延迟,从0.6秒到3.2秒没有区别! 我是对的还是要用另一种方法? reg.AddRange((from a in this.dataContext.reglements join b in this.dataContext.Clients on a.Id_client equals b.Id where a.date_v <= datefin && a.date_v >= datedeb where a.Id_client == b.Id orderby a.date_v descending select new Class_reglement { nom = b.Nom, code = b.code, Numf = a.Numf, }).AsEnumerable().Distinct(new Compare()).ToList()); class Compare : IEqualityComparer<Class_reglement> { public bool Equals(Class_reglement x, […]

IEqualityComparer <T>和IEquatable <T>有什么区别?

我想了解应该使用IEqualityComparer<T>和IEquatable<T>的场景。 两个MSDN文档看起来非常相似。

.NET中的IEqualityComparer <T>中GetHashCode的作用是什么?

我想了解接口IEqualityComparer的GetHashCode方法的作用。 以下示例来自MSDN: using System; using System.Collections.Generic; class Example { static void Main() { try { BoxEqualityComparer boxEqC = new BoxEqualityComparer(); Dictionary<Box, String> boxes = new Dictionary<Box, string>(boxEqC); Box redBox = new Box(4, 3, 4); Box blueBox = new Box(4, 3, 4); boxes.Add(redBox, "red"); boxes.Add(blueBox, "blue"); Console.WriteLine(redBox.GetHashCode()); Console.WriteLine(blueBox.GetHashCode()); } catch (ArgumentException argEx) { Console.WriteLine(argEx.Message); } } […]

IStructuralEquatable和IStructuralComparable能解决什么问题?

我已经注意到这两个接口,以及几个相关的类,已经被添加到.NET 4中。对我来说,这看起来有些多余。 我已经阅读了几篇关于它们的博客,但是我仍然无法弄清楚.NET 4之前他们解决了哪些棘手的问题。 什么用途是结构可以和结构可比较的?

独特的不使用LINQ到对象

class Program { static void Main(string[] args) { List<Book> books = new List<Book> { new Book { Name="C# in Depth", Authors = new List<Author> { new Author { FirstName = "Jon", LastName="Skeet" }, new Author { FirstName = "Jon", LastName="Skeet" }, } }, new Book { Name="LINQ in Action", Authors = new List<Author> { new […]