473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Determining Identity of two Value Types Instances

Let's assume for a moment that i have a function that takes two value type instances:

Expand|Select|Wrap|Line Numbers
  1. public static bool CheckIdentity( ref int a, ref int b )
  2. {
  3. return Object.ReferenceEquals( a, b );
  4. }
  5.  
i need to check parameters a and b for identity, or in other words, return true if they point to the same variable in memory. the ReferenceEquals() function understandably returns false since a and b are boxed as they enter the function. how would i solve this problem?
Dec 26 '07 #1
3 1015
bump. impossible? guh.
Dec 28 '07 #2
Plater
7,872 Expert 4TB
I am not sure you can do it with base datatypes (ints, floats, etc) But I think it would work for complex data types, like custom classes and stuff?
Dec 28 '07 #3
I am not sure you can do it with base datatypes (ints, floats, etc) But I think it would work for complex data types, like custom classes and stuff?
it works on instances of reference types (classes), naturally, because that's what ReferenceEquals was made for. however, value types (structs) are boxed before they are sent to this function, thus ending up with a different memory location of each time.

my question was if there is perhaps a generic function that takes two value parameters by ref and then compares their memory location like that.
Dec 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
1
by: Clemens Hoffmann | last post by:
Hello, i have a nasty problem with object identity in hash tables. I try to use different objects as keys. It failed bacause i cannot identify object propperly. Different objects with the same...
2
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as...
5
by: Stephen Lamb | last post by:
How would one do the following at runtime? I'm really interested in steps 2 and 3. 1. Read data from somewhere that describes types and instances. 2. Construct new types from data. 3....
5
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
41
by: pb648174 | last post by:
In a multi-user environment, I would like to get a list of Ids generated, similar to: declare @LastId int select @LastId = Max(Id) From TableMania INSERT INTO TableMania (ColumnA, ColumnB)...
13
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables...
1
by: chad.poplawski | last post by:
Hi All, I'm working on a Windows Service that uses FileSystemWatcher components to capture and log data when certain actions (such as files being deleted) take place in the file system. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.