The ObjPtr, VarPtr and StrPtr which were found in VB6 were really workarounds due to the limitations of Visual Basic before Visual Basic.NET.
The MSDN documentation in fact says so as: VarPtr, VarPrtArray, VarPtrStringArray, ObjPtr and StrPtr were undocumented functions used to get the underlying memory address of variables. These functions are not supported in Visual Basic .NET.
So if you could explain the scenario where you are using this, it would be easier to provide a solution.
There are no direct equivalents. If all you are doing is using it to compare references then, you can use: ReferenceEquals()
Maybe true in the current implementation but I've never read that the specs guarantee that GetHashCode() will be unique. Where did you get this info from
The advice is to use a custom override for the GetHashCode() function in ur own classes to ensure that it is unique:
MSDN Content: This method can be overridden by a derived class. Value classes must override this method to provide a hash function that is appropriate for the class and that ensures a better distribution in the hash table. Classes that might be used as a key in a hash table must also override this method, because objects that are used as keys in a hash table are required to generate their own hash code through this method. I guess there is no out-of-the-box support for this in .NET.
I guess you could add a custom property to your classes and use the System.Guid class to generate a unique key for each of ur objects.
How to get instance ID of object
Eric Feunteun
The ObjPtr, VarPtr and StrPtr which were found in VB6 were really workarounds due to the limitations of Visual Basic before Visual Basic.NET.
The MSDN documentation in fact says so as:
VarPtr, VarPrtArray, VarPtrStringArray, ObjPtr and StrPtr were undocumented functions used to get the underlying memory address of variables. These functions are not supported in Visual Basic .NET.
So if you could explain the scenario where you are using this, it would be easier to provide a solution.
There are no direct equivalents. If all you are doing is using it to compare references then, you can use: ReferenceEquals()
Regards,
Vikram
Waheed Iqbal
hell0
Why are this functions no longer supported in Visual Basic.NET I love to know.
MichaelMiller
Sergey Ten
Thanks for pointing out. It is not **Unique**.
Just did some check on GetHashCode():
http://blogs.msdn.com/brada/archive/2003/09/30/50396.aspx
So, it cannot after all be used as a unique id!
Regards,
Vikram
Al Edwards
My scenario is that I want to add object to a collection with Key
Dictionory<string, object> objects=new Dictionory<string, Object);
Test object=new Test();
string key= ....//Get object ID here;
objects.Add(key, object);
SALX
MSDN Content:
This method can be overridden by a derived class. Value classes must override this method to provide a hash function that is appropriate for the class and that ensures a better distribution in the hash table. Classes that might be used as a key in a hash table must also override this method, because objects that are used as keys in a hash table are required to generate their own hash code through this method.
I guess there is no out-of-the-box support for this in .NET.
I guess you could add a custom property to your classes and use the System.Guid class to generate a unique key for each of ur objects.
Regards,
Vikram
Scordo
Nemo Wang
See if you can use the GetHashCode() method which is available on every object. It returns a unique integer value for each instance of a class.
object.GetHashCode();
Regards,
Vikram