equals

Overriding GetHashCode for mutable objects? [C#]

I've read about 10 different questions on when and how to override GetHashCode but there's still something I don't quite get. Most implementations of GetHashCode are based on the hash codes of the fields of the object, but it's been cited that the value of GetHashCode should never change over the lifetime of the object. How does that w...

Programmatically Search an Access Listbox control's Items Based Off of a Textbox Entry

I don't know if this is possible, but I am trying to code an Access textbox that will act as a search engine entry control for a database. Specifically, I wanted to add mulitple, non-visible, listboxes to a form, and have them filled with table or query data. When ever an end-user enters a search word in the textbox and presses search,...

A deep struct-like Equals() for .NET classes?

Given two objected that do not contain reference loops within them, do you know a method that tests their equality in a "generic" way (through reflection)? I basically want the same semantics as struct equivalence, only on classes. ...

Most complete Equals implementation for value and reference types respectively

For a reference type (class) like Point3 (for example), is this an overkill, lacking: #region System.Object Members public override bool Equals ( object obj ) { //return this == ( Point3 ) obj; if ( obj == null ) { return false; } if ( this.GetType ( ) != obj.GetType ( ) ) ...

Java: Integer value comparison

I'm a newbie Java coder and I just read a variable of an integer class can be described 3 different ways in the api. I have the following code.. if (count.compareTo(0)) { System.out.println(out_table); count++; } This is inside a loop and just outputs out_table. My goal is the figure out how to see if th...

equality on the sender of an event

I have an interface for a UI widget, two of which are attributes of a presenter. public IMatrixWidget NonProjectActivityMatrix { set { // validate the incoming value and set the field _nonProjectActivityMatrix = value; .... // configure & load non-project activities } public...

Equals method implementation helpers (C#)

Everytime I write some data class, I usually spend so much time writing the IEquatable implementation. The last class I wrote was something like: public class Polygon { public Point[] Vertices { get; set; } } Implementing IEquatable was exaustive. Surely C#3.0/LINQ helps a lot, but the vertices can be shifted and/or in the revers...

Ruby on Rails: what does "equals" symbol mean as a parameter?

Some open source I've been using has the below line as a function declaration: def parse_query(query=nil, options={}, models=nil) What effect do the "equals" symbols have on the statement? Does it just make the parameters optional? ...

Hows to quick check if data transfer two objects have equal properties in C#?

I have these data transfer objects objects: public class Report { public int Id { get; set; } public int ProjectId { get; set; } //and so on for many, many properties. } I don't want to write public bool areEqual(Report a, Report b) { if (a.Id != b.Id) return false; if (a.ProjectId != b.ProjectId) return false; ...

Java string comparison?

String parts is String[6]: [231, CA-California, Sacramento-155328, aleee, Customer Service Clerk, Alegra Keith.doc.txt] But when I compare parts[0] with "231": "231" == parts[0] the above result is false, I'm confused, so could anybody tell me why? ...

How should I go about implementing Object.GetHashCode() for complex equality?

Basically, I have the following so far: class Foo { public override bool Equals(object obj) { Foo d = obj as Foo ; if (d == null) return false; return this.Equals(d); } #region IEquatable<Foo> Members public bool Equals(Foo other) { if (this.Guid != String.Empty && t...

When should you use === vs ==, !== vs !=, etc.. in javascript?

Possible Duplicate: Javascript === vs == : Does it matter which equal operator I use? What are the differences between === and ==, !== and ==... when should you use one and when should you use the other? Matt ...

When "" == s is false but "".equals( s ) is true

EDIT Thanks for the promptly responses. Please see what the real question is. I have make it bold this time. I do understand the difference between == and .equals. So, that's not my question ( I actually added some context for that ) I'm performing the next validation for empty strings: if( "" == value ) { // is empty string }...

Linq: What is the difference between == and equals in a join?

I always wondered why there's an equals keyword in linq joins rather than using the == operator. Property deadline = (from p in properties join w in widgets on p.WidgetID equals w.ID select p).First(); Instead of Property deadline = (from p in properties join w in widgets on p.WidgetID == w.ID select p).First(); [EDIT] Rephra...

How to override equals for specific NHibernate class

I am struggling to figure out how I should override equals and get hashcode for a class I am writing using NHibernate. Basic business scenario is that users cannot re-use the same password within a 90 day limit. So I have a "user" that has many "historical passwords"... the user class was easy as I just use the login in the equals. B...

Single Equals in MYSQL

Hi, I was wondering why MYSQL uses a single equals sign in conditional statements instead of the more typical two equals signs. Is there a technical/historical reason for this? Thanks. ...

How to implement a GetHashCode compatible Equals method, when the space is greater than 32 bits?

In .NET you need that Equals(object) and GetHashCode() are compatible. But sometimes you can't: public class GreaterThan32Bits { public int X { get; set; } public int Y { get; set; } } Because the data density is greater than 32 bits, and GetHashCode returns an Int32, you will have 3 solutions (assuming a correctly implemented...

Is relational comparison between int and float directly possible in C?

I am using Visual Studio 6 with some old time code written in c. I found an issue where the code looks like this.. int x = 3; float y = 3.0; if(x == y){ do some crazy stuff } is this a valid comparison? is it possible at run time the allocation for the float is 3.0000001 and this would fail? I am a rookie so take it easy on me :...

Optimizing equals() method

The equals() method (and for that matter, also the compareTo() method) can become a performance hotspot (e.g. in a high-traffic HashMap). I was wondering what tricks folks have adopted to optimize these methods for these cases when they prove necessary. IntelliJ IDEA, for example, generates the following: public boolean equals(Object o...

Should one override equals method for asserting the object equality in a unit test?

Let's say we are testing the result of a method by asserting the equality of all the properties of the result object with properties of an expected result object. Should we implement equals method and use Assert.AreEqual(expectedResult, actualResult)... But equals may mean something different in production code. Which is the best prac...