Question: As the title implies, I want to compare two objects whose type may be diffrent.

For eg,
I expects 'true' for comparing 1000.0(Decimal) with 1000(Double) .
Similary, it should return true if I compare 10(string) and 10(double) .

I tried to compare using Object.Equals() , but it did NOT work.It return false if two objects have different data types.

```
Dim oldVal As Object  ' assgin some value
Dim newVal As Object  'assgin some value
If Not Object.Equals(oldVal,newVal) Then
  'do something
End If

```

**Edit:**
Could it be possible if I do the below?

```
    1.check the type of oldVal
    2.Covert the type of newVal to oldVal
    3.Compare.

```

Answer: 
Try this:

```
Dim oldVal As Object  'assgin some value
Dim newVal As Object  'assgin some value
Dim b As Boolean = False

If IsNumeric(oldVal) And IsNumeric(newVal) Then
    b = (Val(oldVal) = Val(newVal))
ElseIf IsDate(oldVal) And IsDate(newVal) Then
    b = (CDate(oldVal) = CDate(newVal))
Else
    b = (oldVal.ToString() = newVal.ToString())
End If

If Not b Then
    'do something
End If

```

Or use IIf like this:

```
If Not CBool(IIf(IsNumeric(oldVal) And IsNumeric(newVal), 
                  (Val(oldVal) = Val(newVal)),
                  IIf(IsDate(oldVal) And IsDate(newVal), 
                     (CDate(oldVal) = CDate(newVal)), 
                     (oldVal.ToString() = newVal.ToString())))) Then
    'do something
End If

```
there are a couple of ways you could do this, below is the one i feel that is closest to what you're looking for, though personally I dont think its a good way to structure your solution.

```

Dim fooObj As New Foo
Dim barObj As New Bar

fooObj.Value = 10
barObj.Value = 10

System.Diagnostics.Debug.WriteLine(barObj.Equals(fooObj))
System.Diagnostics.Debug.WriteLine(barObj.Equals(barObj))
System.Diagnostics.Debug.WriteLine(barObj.Equals(10))
System.Diagnostics.Debug.WriteLine(barObj.Equals(20))
System.Diagnostics.Debug.WriteLine(barObj.Equals("10"))
System.Diagnostics.Debug.WriteLine(barObj.Equals("20"))

System.Diagnostics.Debug.WriteLine(Object.Equals(barObj, 10))

```

```

Public Class Foo
    Public Value As Integer
End Class

Public Class Bar
    Public Value As Integer

    Public Overrides Function Equals(ByVal obj As Object) As Boolean

        If TypeOf obj Is Bar Then
            Dim compareBar As Bar = DirectCast(obj, Bar)

            Return MyClass.Value = compareBar.Value

        ElseIf TypeOf obj Is Foo Then
            Dim compareFoo As Foo = DirectCast(obj, Foo)

            Return MyClass.Value = compareFoo.Value

        ElseIf TypeOf obj Is Integer Then
            Dim compareInt As Integer = DirectCast(obj, Integer)

            Return MyClass.Value = compareInt

        ElseIf TypeOf obj Is String Then
            Dim compareString As String = DirectCast(obj, String)

            Return MyClass.Value.ToString() = compareString
        End If

        Return False

    End Function
End Class

```