Prev | Current Page 360 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

1, Decimal))
'Send new salary to console.
Console.WriteLine("Employee's new salary = {0:C}", e.Salary)
Next
End Sub
End Class
CHAPTER 11 n DELEGATES AND EVENTS 225
Here are the employees??™ salaries after their raises:
Employee's new salary = $44,000.00
Employee's new salary = $71,500.00
Employee's new salary = $104,500.00
The declaration of the delegate has an Employee type declared at the beginning of the
parameter list. This is how you expose the hidden instance pointer so that you can bind
it later. Had you used this delegate to represent a closed-instance delegate, the Employee
parameter would have been omitted. Unfortunately, VB doesn??™t have any special syntax for
creating open-instance delegates. Therefore, you must use one of the more generalized
Delegate.CreateDelegate() overloads to create the delegate instance as shown; but before
you can do that, you must use reflection to obtain the MethodInfo instance representing the
method to bind to.
Nowhere during the instantiation of the delegate do you provide a specific object
instance. You won??™t provide that until the point of delegate invocation. The For Each loop
shows how you invoke the delegate and provide the instance to call upon at the same time.
Even though the ApplyRaiseOf method that the delegate is wired to takes only one parameter,
the delegate invocation requires two parameters so that you can provide the instance on
which to make the call.


Pages:
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
London Escort Agencies katalog stron Connie Talbot dieta light fenomenalne mieszkania do wynajęcia warszawa