Wednesday, March 28, 2012

String.Equals Wrong Parameter ?

In VisStudio.Net 1,0, I am receiving the error "Parameter is Incorrect" on lines 5, 6, and 7 below. Line 8 works correctly. This is code I picked up from the MSFT website - any ideas as to what could be wrong with it?

Thanks
Mike Thomas

1 Dim sb As New StringBuilder("abcd")
2 Dim str1 As [String] = "abcd"
3 Dim str2 As [String] = Nothing
4 Dim o2 As [Object] = Nothing

5 ? str1.Equals(sb)
6 ? str1.Equals(o2)
7 ? str1.Equals(str2)
8 ? [String].Equals(str1, str2)

At top is

Imports System.String
Imports System.TextHi,

my guess would be that you have Option Strict set to On so that you have to cast specifically. Try something like this:


str1.Equals(sb.ToString)

Grz, Kris.
Many thanks Kris - that was exactly it.

Mike Thomas

0 comments:

Post a Comment