Click here to Skip to main content
15,906,628 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to open Image n Video file header in c# Pin
Dave Kreskowiak29-Oct-09 10:39
mveDave Kreskowiak29-Oct-09 10:39 
AnswerRe: how to open Image n Video file header in c# Pin
Abhishek Sur29-Oct-09 10:40
professionalAbhishek Sur29-Oct-09 10:40 
GeneralRe: how to open Image n Video file header in c# Pin
Christian Graus29-Oct-09 12:06
protectorChristian Graus29-Oct-09 12:06 
GeneralRe: how to open Image n Video file header in c# Pin
shrikant121329-Oct-09 15:33
shrikant121329-Oct-09 15:33 
GeneralRe: how to open Image n Video file header in c# Pin
Christian Graus29-Oct-09 18:47
protectorChristian Graus29-Oct-09 18:47 
GeneralRe: how to open Image n Video file header in c# Pin
shrikant121330-Oct-09 6:15
shrikant121330-Oct-09 6:15 
QuestionObject.Equals(object one, object two) vs Object.ReferenceEquals(object one, object two) [SOLVED] Pin
CaptainSeeSharp29-Oct-09 8:16
CaptainSeeSharp29-Oct-09 8:16 
AnswerRe: Object.Equals(object one, object two) vs Object.ReferenceEquals(object one, object two) Pin
Ian Shlasko29-Oct-09 8:34
Ian Shlasko29-Oct-09 8:34 
The answer is simpler than you think... Here's an example:
public class MyClass
{
  public string Value { get; set; }

  public override bool Equals(object obj)
  {
     MyClass other = obj as MyClass;
     return (other != null && other.Value == Value);
  }
}

MyClass a = new MyClass() { Value = "Test" };
MyClass b = new MyClass() { Value = "Test" };


Now... These are two entirely different objects, that happen to contain the same contents. In this case, Equals() returns true, but ReferenceEquals() returns false.

The basic concept is that Equals() indicates logical equivalence... Dunno if that's the right term... It tests whether the two objects are equivalent in terms of what they contain (At least, it's supposed to - You're supposed to override it in classes you create). ReferenceEquals() always tests whether two references point to the same physical object in memory.

EDIT:
CaptainSeeSharp wrote:
if (ReferenceEquals(this, obj)) return true; //why use Object.ReferenceEquals here and not Object.Equals(obja, objb)?
//They do the same exact thing as far as I can tell


To add... That's a shortcut. ReferenceEquals() is a much faster operation, since you're just testing whether two pointers are equal. Obviously if the two references point to the same object, testing Equals() (Which may have a lengthy implementation, such as comparing every element in an array) is superfluous.

Proud to have finally moved to the A-Ark. Which one are you in?
Developer, Author (Guardians of Xen)

GeneralRe: Object.Equals(object one, object two) vs Object.ReferenceEquals(object one, object two) Pin
Henry Minute29-Oct-09 8:36
Henry Minute29-Oct-09 8:36 
GeneralRe: Object.Equals(object one, object two) vs Object.ReferenceEquals(object one, object two) Pin
CaptainSeeSharp29-Oct-09 8:47
CaptainSeeSharp29-Oct-09 8:47 
AnswerRe: Object.Equals(object one, object two) vs Object.ReferenceEquals(object one, object two) Pin
Henry Minute29-Oct-09 8:34
Henry Minute29-Oct-09 8:34 
GeneralRe: Object.Equals(object one, object two) vs Object.ReferenceEquals(object one, object two) [modified] Pin
CaptainSeeSharp29-Oct-09 8:40
CaptainSeeSharp29-Oct-09 8:40 
Questionmake video Pin
behzadcp29-Oct-09 7:38
professionalbehzadcp29-Oct-09 7:38 
AnswerRe: make video Pin
Henry Minute29-Oct-09 8:39
Henry Minute29-Oct-09 8:39 
AnswerRe: make video Pin
EliottA29-Oct-09 8:40
EliottA29-Oct-09 8:40 
GeneralRe: make video Pin
_Madmatt29-Oct-09 9:46
_Madmatt29-Oct-09 9:46 
GeneralRe: make video Pin
EliottA29-Oct-09 9:49
EliottA29-Oct-09 9:49 
GeneralRe: make video Pin
_Madmatt29-Oct-09 9:56
_Madmatt29-Oct-09 9:56 
GeneralRe: make video Pin
EliottA29-Oct-09 9:58
EliottA29-Oct-09 9:58 
GeneralRe: make video Pin
_Madmatt29-Oct-09 10:02
_Madmatt29-Oct-09 10:02 
GeneralRe: make video Pin
EliottA29-Oct-09 10:03
EliottA29-Oct-09 10:03 
GeneralRe: make video Pin
_Madmatt29-Oct-09 10:05
_Madmatt29-Oct-09 10:05 
GeneralRe: make video Pin
EliottA29-Oct-09 10:06
EliottA29-Oct-09 10:06 
GeneralRe: make video Pin
_Madmatt29-Oct-09 10:08
_Madmatt29-Oct-09 10:08 
GeneralRe: make video Pin
EliottA29-Oct-09 10:40
EliottA29-Oct-09 10:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.