I'm learning delegates in VB.NET and am confused about delegate types. In reading about delegates, I learned that delegates are a data type that can refer to a method with a particular kind of signature. So in the same way that a String can refer to characters, a delegate can refer to a method (for instance) that takes an integer as input and returns an integer as output. But in playing around with delegates, I found that this was not the case. The code below compiles and runs--even though I don't obey the 'typing' in my delegate signature. I'm confused. Am I missing something?
Public Delegate Function myDelegate(ByVal i As Integer) As Integer' int in, rtrn int
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim md As myDelegate 'should be of type int in, rtrn int
md = New myDelegate(AddressOf squared) 'allows assign to string in, string out
MsgBox(md("3"))
End Sub
Private Function squared(ByVal i As String) As String
Return i * i
End Function