How does ReferenceEquals fuction work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Holbox

    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("equa ls?:" & referenceequals (a,b))

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

    system.console. readline()
    end sub

    Why?

    Thx
  • Jon Skeet [C# MVP]

    #2
    Re: How does ReferenceEquals fuction work?

    Holbox <informacion@ya .com> wrote:[color=blue]
    > 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("equa ls?:" & referenceequals (a,b))
    >
    > // this will return "FALSE"
    > system.console. writeline("equa ls?:" & referenceequals (c,d))
    >
    > system.console. readline()
    > end sub
    >
    > Why?[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...