none
compare two value by .EQUALS RRS feed

  • Question

  • Hi all

    I woulk like to know if the two IFs do the same thing in the property

    Public Property InfoGroupOn As GroupingInfo
        Get
            Return myInfoGroupOn
        End Get
        Set(ByVal value As GroupingInfo)
            If myInfoGroupOn = value Then Return
          
            If value.Equals(myInfoGroupOn) Then Return
    
            setgroupon(value, Options.AlwaysGroupOnText)
            
        End Set
    End Property
               


    Monday, September 3, 2018 5:04 PM

Answers

  • In my opinion, if GroupingInfo is a class, then value.Equals invokes the Equals member, if any. Otherwise it simply compares the references.

    In contrast, ‘=’ invokes the ‘=’ operator (defined with ‘Operator =’ keyword).

    However, value.Equals will not work when value is Nothing (null). But ‘=’ will work.


    • Edited by Viorel_MVP Monday, September 3, 2018 9:00 PM
    • Marked as answer by Claudio111 Wednesday, September 5, 2018 5:19 AM
    Monday, September 3, 2018 8:44 PM
  • Hi,

    For value types, the operator (=) returns true if the values of the objects are equal, otherwise returns false. For reference types other than string, = returns true if two objects refer to the same object. For the string type, = compares the value of the string.
    The = operation compares whether the values of the two variables are equal.
    The equals() method compares whether the contents of two objects are consistent. Equals is to compare whether the reference type is a reference to the same object.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Wednesday, September 5, 2018 5:19 AM
    Tuesday, September 4, 2018 6:21 AM

All replies

  • In my opinion, if GroupingInfo is a class, then value.Equals invokes the Equals member, if any. Otherwise it simply compares the references.

    In contrast, ‘=’ invokes the ‘=’ operator (defined with ‘Operator =’ keyword).

    However, value.Equals will not work when value is Nothing (null). But ‘=’ will work.


    • Edited by Viorel_MVP Monday, September 3, 2018 9:00 PM
    • Marked as answer by Claudio111 Wednesday, September 5, 2018 5:19 AM
    Monday, September 3, 2018 8:44 PM
  • Hi,

    For value types, the operator (=) returns true if the values of the objects are equal, otherwise returns false. For reference types other than string, = returns true if two objects refer to the same object. For the string type, = compares the value of the string.
    The = operation compares whether the values of the two variables are equal.
    The equals() method compares whether the contents of two objects are consistent. Equals is to compare whether the reference type is a reference to the same object.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Wednesday, September 5, 2018 5:19 AM
    Tuesday, September 4, 2018 6:21 AM