Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / June 2005

Tip: Looking for answers? Try searching our database.

How to check for same object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Thielen - 14 Jun 2005 03:38 GMT
Hi;

How can I check if two objects in C# are the same object? (ie the C++
equivilent of comparing pointer values.)

o1 == o2 won't do it if the equals method compares values.

Signature

thanks - dave

David Thielen - 14 Jun 2005 03:53 GMT
Oh - and in my case, one of these objects is a COM wrapper (marshalled) object.

Signature

thanks - dave

> Hi;
>
> How can I check if two objects in C# are the same object? (ie the C++
> equivilent of comparing pointer values.)
>
> o1 == o2 won't do it if the equals method compares values.
"Peter Huang" [MSFT] - 14 Jun 2005 06:36 GMT
Hi David,

I think you may try the method
Object.ReferenceEquals Method
Example
[C#, C++, JScript] The following code example uses ReferenceEquals to
determine if two objects are the same instance.

[C#]
using System;

class MyClass {

  static void Main() {
     object o = null;
     object p = null;
     object q = new Object();

     Console.WriteLine(Object.ReferenceEquals(o, p));
     p = q;
     Console.WriteLine(Object.ReferenceEquals(p, q));
     Console.WriteLine(Object.ReferenceEquals(o, p));
  }
}

/*

This code produces the following output.

True
True
False

*/

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

David Thielen - 14 Jun 2005 15:03 GMT
Perfect - thank you

Signature

thanks - dave

> Hi David,
>
[quoted text clipped - 38 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 15 Jun 2005 02:50 GMT
Hi

You are welcome!

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.