473,387 Members | 1,573 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,387 software developers and data experts.

How does ReferenceEquals fuction work?

Hi people,
look at this (console project)

sub main
dim a as string = "Hola"
dim b as string = "Hola"
dim c as string = new string("Hola")
dim d as string = new string("Hola")

// this will return "TRUE"
system.console.writeline("equals?:" & referenceequals(a,b))

// this will return "FALSE"
system.console.writeline("equals?:" & referenceequals(c,d))

system.console.readline()
end sub

Why?

Thx
Jul 21 '05 #1
1 1574
Holbox <in*********@ya.com> wrote:
look at this (console project)

sub main
dim a as string = "Hola"
dim b as string = "Hola"
dim c as string = new string("Hola")
dim d as string = new string("Hola")

// this will return "TRUE"
system.console.writeline("equals?:" & referenceequals(a,b))

// this will return "FALSE"
system.console.writeline("equals?:" & referenceequals(c,d))

system.console.readline()
end sub

Why?


Because c and d are references to two different string objects, whereas
a and b are references to the same string object.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin B Ebert | last post by:
Today, I ran into something I didn't quite expect. I'm sure there is a logical explanation for it so I want to post it and see if anyone can explain the difference to me. I came across a...
6
by: Daniel Billingsley | last post by:
In C# these are equivalent, right? if (ReferenceEquals(objectA, objectB)) { } and if (objectA == objectB) {
3
by: Fei Li | last post by:
Hi, take string class as an example, who can explain the difference? Thanks
3
by: mike | last post by:
i've already used static fuction to make website i wanna common module that's why i used static fuctions. may be it's more than 100 fuction ...is it ok?
1
by: Holbox | last post by:
Hi people, look at this (console project) sub main dim a as string = "Hola" dim b as string = "Hola" dim c as string = new string("Hola") dim d as string = new string("Hola")
4
by: Kiran A K | last post by:
hi, consider the following piece of code: string s1 = "kiran"; string s3 = s1.Clone() as string; Console.WriteLine(System.Object.ReferenceEquals(s1, s3)); The above piece of code gave me...
20
by: Marcel Hug | last post by:
Hi NG! In my book I have the following code simple and I tested it: public class Base : ICloneable { public int Age; public string Name; public Base(string myname)
4
by: Karen Hill | last post by:
How does one check if an object's reference is null? I'd like to check that rather than catch a nullreference exception. thanks.
21
by: Ray Cassick | last post by:
I can't believe why I had not noticed this before and why I never asked it before... When defining a string why is it not required to use the new keyword? Like: Dim a As String = New String ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.