How does ReferenceEquals fuction work?

  • Thread starter Thread starter Holbox
  • Start date Start date
H

Holbox

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
 
Holbox said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top