Question Solution builds altough there are errors

stehtimschilf

New member
Joined
Sep 3, 2009
Messages
4
Programming Experience
Beginner
Hi Forum

Why does the IDE compiles this classes without any error messages?

VB.NET:
Public Class TestClass1
    Public Shared Function test1() As String
        Return ""
    End Function
End Class

Public Class TestClass2
    Public Shared Sub test()
        Dim s As String = TestClass1.test1(2)
    End Sub
End Class

The test1()-function has no parameters! But the IDE does not complain. During run time i'll get finally the error:
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

If I call test1() with
VB.NET:
TestClass1.test1("2")
I'll get an error:
Option Strict On disallows implicit conversions from 'String' to 'Integer'.

I dont get it.....?

cheerioh
SiS
 
Function test1() returns a String, and a String can be indexed as a Char array through the default Chars property, the index parameter is Integer type. TestClass1.test1(2) would be same as TestClass1.test1.Chars(2)
 
Back
Top