Results 1 to 3 of 3

Thread: comparing values

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    comparing values

    Is there an easy and quick way to compare values of 2 objects?
    I have a function that accepts 2 parameters of object type.
    I want to see if the values are the same or different.
    The 2 objects will always be of the same type.
    however the function can be called from many places and different types can be passed in.
    The objects can also be nothing at times.

    Thanks,
    Don't anthropomorphize computers -- they hate it

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: comparing values

    How can the system possibly know how to compare two objects unless you tell it? If a type implements the IComparable interface then its author has already told the system how to compare two objects of that type. In that case there IS an easy way to compare them. Otherwise there isn't. In that case you would have to write your own code to compare two instances of each type you might want to compare.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: comparing values

    John is correct. The only way you can just do a standard equals using the object base class is to check for reference equality, but I am sure that is not what you are looking to do.

    Otherwise you need to write code to determine how to check for equality

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width