O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.5. Script Blocks as Delegates

Delegates are an integral part of .NET's event handling mechanism. In short, delegates are objects that keep a reference to a .NET class, a method reference, and an object reference if the method is not static. When a delegate is invoked, it will call the method of the object it references. Events in .NET are implemented as delegates pointing to the event receiver object and method, and passing those delegates to the event sender. The sender invokes the event delegates when it raises the event, and the receiver gets notified.

Script blocks and delegates have a lot in common—both of them point to some code and can be invoked to execute that code. PowerShell's type system allows a script block to be converted to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required