473,397 Members | 2,077 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.

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 1575
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.