Why does the sender behave like it was passed as byref?
is not the sender passed as byval? If so, why does the sender object behave as if it were passed as byref. We were able to change the button text on the button sender, apparently in the code below.
Private Sub Button_Click(byval sender As Object,byval e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
DirectCast(sender, Button).Text = "You clicked me!"
End Sub
+3
source to share
2 answers
A copy of the reference to the sender is passed to the method. This means that when you change the text, you change it on the same object. I suggest you read this great article by Jon Skeet: Parameters
+3
source to share