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.
 
Back
Top