why "CType(sender,....", instead of the object, itself?
Posted on 2007-12-05
I am studying for the MCAD 70-306 exam, using Gunderloy. I notice that he often has code such as the following:
Private Sub dudColor_SelectedItemChanged( ByVal sender As System.Object, ByVal e As ystem.EventArgs) _
' Typecast the object to DomainUpDown
Dim dudCol As DomainUpDown = CType(sender, DomainUpDown)
' Change color of lblsampleText to selected color
lblSampleText.ForeColor = Color.FromName(dudCol.Text)
My question is, since you have access to dudColor, why bother with
Dim dudCol As DomainUpDown = CType(sender, DomainUpDown) ???
Why can't you, or shouldn't you, just write:
lblSampleText.ForeColor = Color.FromName(dudColor.Text) ???