Hi,
I have a class A that implements IEquatable<>, using its fields (say, A.b and A.c) for implementing/overriding Equals() and overriding GetHashCode(), and everything works fine, 99% of the time. Class A is part of a hierarchy (class B, C) that all inherit from interface D; they can all be stored together in a dictionary Dictionary, t...
Hello,
How do i check the key in dictionary is same as the string in method parameter?
i.e in below code , dictobj is NSMutableDictionary's object , and for each key in dictobj i need to compare with string. How to achieve this ? Should i typecase key to NSString??
-(void)CheckKeyWithString:(NSString *)string
{
//foreach key in NSMu...
I have a class called
MyClass
This class inherits IEquatable and implements equals the way I need it to. (Meaning: when I compare two MyClass tyupe objects individually in code, it works)
I then create two List:
var ListA = new List<MyClass>();
var ListB = new List<MyClass>();
// Add distinct objects that are equal to one another t...
I'm trying to implement a custom comparer on two lists of strings and use the .Except() linq method to get those that aren't one one of the lists. The reason I'm doing a custom comparer is because I need to do a "fuzzy" compare, i.e. one string on one list could be embedded inside a string on the other list.
I've made the following com...
Im writing my own LINQ reference but Im getting troubles with some of the more complicated operators implementations.
There is a Join implementation that takes a IEqualityComparer Im getting just crazy.
Im trying to understand it first before I write (obviously)
Image this two lists:
List<string> initials = new List<string> {"A", "B"...
If I have an object of type MyBull and a List<MyBull> orig:
// Just an example
MyBull x = getMeTheObjectWithIdFromDB(9);
orig.add(x);
// Again same? data object
MyBull y = getMeTheObjectWithIdFromDB(9);
Why is this false then?
// This is false, even though all the properties
// of x and y are the same.
orig.Contains<MyBull>(y);
...
I am looking at System.Collections.Specialized.NameValueCollection and it takes an IEqualityComparer, which is good news if someone like me wanted to sort the items in the collection by, say, something like the alphabetical order of the keys.
But, on a closer look in Reflector, I don't see the NVC class actually using the IEqualityCompa...
Hi all,
which is the best implementation for IEqualityComparer for this class ??
The entity has 7 properties.
Thanks in advanced.
[Serializable()]
public class ServidorSeleccionadoDto
{
[XmlAttribute()]
public int Id { get; set; }
[XmlAttribute()]
public string Nombre { get; set; }
[X...
Hello guys!
Take a look at this class:
public class MemorialPoint:IMemorialPoint,IEqualityComparer<MemorialPoint>
{
private string _PointName;
private IPoint _PointLocation;
private MemorialPointType _PointType;
private DateTime _PointStartTime;
private DateTime _PointFinishTime;
private string _NeighborName;
...
I happened to have seen some code where this guy passed a lambda expression to a ArrayList.Sort(IComparer here) or a IEnumerable.SequenceEqual(IEnumerable list, IEqualityComparer here) where an IComparer or an IEqualityComparer was expected.
I can't be sure if I saw it though, or I am just dreaming. And I can't seem to find an extension...
This will probably be an extremely simple question. I'm simply trying to remove duplicate byte[]s from a collection.
Since the default behaviour is to compare references, I tought that creating an IEqualityComparer would work, but it doesn't.
I've tried using a HashSet and LINQ's Distinct().
Sample code:
using System;
using System.Co...
i see that the IEqualityComparer interface has Equals(obj x, obj y) and GetHashcode().
I fully understand the Equals() methods because i you have to say if two things are the same or not but why do i need to implement a GetHashCode() method as well?
...
hi, i'm writing an interesting program, and every performance hit is very painful for me.
so i'm wondering what is better - to make an extra "if" statement to reduce a number of function calls, or to avoid those "if" adn get more funciton calls. the function is virtual method, that overrides IEqualityComparer's method Equals, all it does...
I've noticed these two interfaces, and several associated classes, have been added in .NET 4. They seem a bit superfluous to me; I've read several blogs about them, but I still can't figure out what problem they solve that was tricky before .NET 4.
What use are IStructuralEquatable and IStructuralComparable?
...
I want to compare two values at runtime using reflection. I was using Comparer.Default.Compare(x,y) for this, but I have come to realize that this is not adequate. Let's say I want to compare a double to a single (1.0 == 10). Comparer.Default will throw an exception because it insists that both values must be the same type (double). Howe...