Все вопросы: [iequalitycomparer]
14 вопросов
Remove duplicates from DataTable and custom IEqualityComparer<datarow></datarow>
How have I to implement IEqualityComparer<DataRow> to remove duplicates rows from a DataTable with next structure: ID primary key, col_1, col_2, col_3, col_4 The default comparer doesn't work because each row has it's own, unique primary key. How to implement IEqualityComparer<DataRo...
C# - List<t>.Remove() always deletes the first object on the list</t>
Working in Visual Studio 2008 (C#)... I use a List collection to store instances of my custom class (Shift). I want to delete a certain shift from the list by using the Remove method. But List.Remove() always deletes the first item it finds. I've implemented the IComparable interface for my Shift...
Hashtables (Dictionary etc) with integer keys
I've been puzzling over this for a few days... feel free to shoot down any of my assumptions. We're using a Dictionary with integer keys. I assume that the value of the key in this case is used directly as the hash. Does this mean (if the keys are grouped over a small range) that the distributio...
Distinct not working with LINQ to Objects
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 ...
Hashsets and different instances of class with all members identical
Let's say I have a class called myclass. In my code I have two instances of myclass, myclass1 and myclass2. Everything about them is (public and private) properties are identical. If I try to add both of them to a HashSet will it add both or only one? If it adds both and I don't want it to, can...
IEnumerable.Except() and a custom comparer
I'm having troubles with the Except() method. Instead of returning the difference, it returns the original set. I've tried implementing the IEquatable and IEqualityComparer in the Account class. I've also tried creating a separate IEqualityComparer class for Account. When the Except() method i...
Is there a way to find an object's properties in List<t> using Contains?</t>
I was wandering how can I find out if an object already exists in my List. I'm adding "newPerson" (instance of Person class) in a List, but checking if newPerson contents/properties exists or not in the List. This piece works fine: List<Person> people = this.GetPeople(); i...
IEqualityComparer для анонимного типа
У меня есть это var n = ItemList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor, s.Description, s.Invoice }).ToList(); n.AddRange(OtherList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor, s.Description, s.Invoice }).ToList();); Я хотел бы сделать это, если это разрешено n = n...
LINQ, кроме использования настраиваемого Comparer
Я пытаюсь использовать метод «Except» в наборе результатов LINQ с использованием настраиваемой реализации, если IEqualityComparer исключит определенные результаты на основе значения одного поля из набора результатов. Итак, в упрощенном виде у меня ... '' Get collection of published sites.....
Custom Generic.IEqualityComparer (Of T) - Ошибки компилятора
Я пытаюсь реализовать простой IEqulityComparer для использования с коллекциями LINQ. Я написал следующий код, который сокращен до его простейшей формы для обсуждения ... Public Structure bob Dim SiteID As Integer Dim fred As String End Structure Public Class insCompare Implements...
Конструктор HashSet с настраиваемым IEqualityCompare, определяемым лямбдой?
В настоящее время конструктором HashSet<T>, который позволяет вам самостоятельно определять сравнение на равенство, является конструктор HashSet<T>(IEqualityComparer<T> comparer). Я хотел бы определить этот EqualityComparer как лямбду. Я нашел это сообщение в блоге , которы...
IEqualityComparer.Equals при использовании с IEnumerable.Contains является ли x или y значением в списке?
IEnumberable имеет метод расширения Contains , который принимает два параметра. Первый параметр - это значение, которое нужно проверить, а второй - реализация IEqualityComparer. Если посмотреть на IEqualityComparer.Equals, потребуется два параметра с именами x и y для сравнения первого и второго...
Как реализовать IEqualityComparer <t> в VB.NET?</t>
У меня есть следующая функция, которая просматривает каталог и проверяет указанную папку и файл: Private Function VerifyPath(ByVal root As String, ByVal folder As String, _ ByVal file As String) As Boolean Dim folders As New List(Of String), files As New List...
C # 3.0: необходимо вернуть дубликаты из списка <>
У меня есть List <> объектов в C #, и мне нужен способ вернуть те объекты, которые считаются дубликатами в списке. Мне не нужен набор результатов Distinct, мне нужен список тех элементов, которые я буду удалять из своего репозитория. Для этого примера допустим, что у меня есть список ти...