tagged [equals]
Compare two List<T> objects for equality, ignoring order
Compare two List objects for equality, ignoring order Yet another list-comparing question. I need to check that they both have the same elements, regardless of their position within the list. Each obj...
- Modified
- 7 Jan at 16:56
C# Differences between operator ==, StringBuilder.Equals, Object.Equals and Object.ReferenceEquals
C# Differences between operator ==, StringBuilder.Equals, Object.Equals and Object.ReferenceEquals I have a question about `Object.Equals` and `Equals(object)`. My sample code is below: ``` class Prog...
- Modified
- 23 Jul at 05:14
Getting an element from a Set
Getting an element from a Set Why doesn't `Set` provide an operation to get an element that equals another element? I can ask whether the `Set` contains an element equal to `bar`, so why can't I get t...
- Modified
- 24 Feb at 19:46
What's the best strategy for Equals and GetHashCode?
What's the best strategy for Equals and GetHashCode? I'm working with a domain model and was thinking about the various ways that we have to implement these two methods in .NET. What is your preferred...
- Modified
- 28 Nov at 23:50
Integer value comparison
Integer value comparison I'm a newbie Java coder and I just read a variable of an integer class can be described three different ways in the API. I have the following code: This is inside a loop and j...
- Modified
- 13 May at 10:12
Is it possible for 'this' keyword to equal null?
Is it possible for 'this' keyword to equal null? In an example, my professor has implemented Equals as follows: I have no
How to quickly check if two data transfer objects have equal properties in C#?
How to quickly check if two data transfer objects have equal properties in C#? I have these data transfer objects: I don't want to write ``` public bool areEqual(Report a, Report b) { if (a.Id != b....
How do I check if an object is equal to a new object of the same class?
How do I check if an object is equal to a new object of the same class? If I have a object like: And I want the behavior: and that a == b returns true, do I have to override the Object.Equals() method...
What's the difference between IEquatable and just overriding Object.Equals()?
What's the difference between IEquatable and just overriding Object.Equals()? I want my `Food` class to be able to test whenever it is equal to another instance of `Food`. I will later use it against ...
- Modified
- 1 Aug at 04:32
Any reason to prefer getClass() over instanceof when generating .equals()?
Any reason to prefer getClass() over instanceof when generating .equals()? I'm using Eclipse to generate `.equals()` and `.hashCode()`, and there is an option labeled "Use 'instanceof' to compare type...
- Modified
- 27 Feb at 20:14
Comparing object used as Key in Dictionary
Comparing object used as Key in Dictionary my class: and main example: ``` Dictionary> dict = new Dictionary>(); myClass first = new myClass(); first.A = 2; first.B = 3; myClass second = new m
- Modified
- 19 Jul at 14:28
Equals method of System.Collections.Generic.List<T>...?
Equals method of System.Collections.Generic.List...? I'm creating a class that derives from List... > `public class MyList : List {}` I've overridden Equals of MyListItem... I would like to have an Eq...
BigDecimal equals() versus compareTo()
BigDecimal equals() versus compareTo() Consider the simple test class: ``` import java.math.BigDecimal; /** * @author The Elite Gentleman * */ public class Main { /** * @param args */ public s...
- Modified
- 22 Jul at 08:52
C# SortedSet<T> and equality
C# SortedSet and equality I am a bit puzzled about the behaviour of SortedSet, see following example: ``` public class Blah { public double Value { get; private set; } public Blah(double value) ...
Overriding Equals method in Structs
Overriding Equals method in Structs I've looked for overriding guidelines for structs, but all I can find is for classes. At first I thought I wouldn't have to check to see if the passed object was nu...
- Modified
- 8 May at 13:7
Compare two objects with .equals() and == operator
Compare two objects with .equals() and == operator I constructed a class with one `String` field. Then I created two objects and I have to compare them using `==` operator and `.equals()` too. Here's ...
Equals(item, null) or item == null
Equals(item, null) or item == null Is code that uses the [static Object.Equals](http://msdn.microsoft.com/en-us/library/w4hkze5k.aspx) to check for null more robust than code that uses the == operator...
- Modified
- 17 Aug at 22:11
compareTo() vs. equals()
compareTo() vs. equals() When testing for equality of `String`'s in Java I have always used `equals()` because to me this seems to be the most natural method for it. After all, its name already says w...
Why comparing two strings as object causes unexpected result
Why comparing two strings as object causes unexpected result Consider the following piece of code. I understand the equality operator working here that as we have implicitly casted
- Modified
- 13 Jul at 11:52
Overloading operator== versus Equals()
Overloading operator== versus Equals() I'm working on a C# project on which, until now, I've used immutable objects and factories to ensure that objects of type `Foo` can always be compared for equali...
- Modified
- 25 Sep at 20:17
Setting equal heights for div's with jQuery
Setting equal heights for div's with jQuery I want to set equal height for divs with jQuery. All the divs may have different amount of content and different default height. Here is a sample of my html...
What is Type.GUID and how does it relate to Type.Equals()?
What is Type.GUID and how does it relate to Type.Equals()? I came across some interesting behavior while trying to compare an instance of `System.RuntimeType` with a generic type `TOut`: ``` Type runt...
Why private members of a class instance are getting available in Equals() method body?
Why private members of a class instance are getting available in Equals() method body? > [Why are my privates accessible?](https://stackoverflow.com/questions/5244997/why-are-my-privates-accessible) ...
How do I check if two Objects are equal in terms of their properties only without breaking the existing Object.Equals()?
How do I check if two Objects are equal in terms of their properties only without breaking the existing Object.Equals()? Basically, GethashCode is different even though they contain the SAME values fo...