Thursday, July 30, 2009

Hi just got a question about c# sharp in visual studio?

Determining if two references refer to the same object should be done using:





1. The Object.ReferenceEquals method.


2. The == operator.


3. The Equals method.





I get the feeling that it is number 1, as the other two are comparing values but am I right? Any thoughts are much appreciated, many thanks in advance

Hi just got a question about c# sharp in visual studio?
Hi,





i am sure it is not == operator nor Equals method and ReferenceEquals Methods doesn't exists but .......








why you are doing that ?





if you are afraid that references will be overwritten please don't





if u are doing good logic in programming u shouldn't be afraid of references overwriting or memory allocation





I wish that could help





Abdelrahman
Reply:It depends on if you are comparing for the address of an object or if the objects have the same data.





If you want to know if the objects are pointing to the same ADDRESS, use #1.





If you create objects, overload the == operator and use that to determine if the objects have the same data, not address.


No comments:

Post a Comment