Lexical Closures
To provide support for lambda expressions, the Visual Basic compiler implements a background feature known as lexical closures. Before going into the explanation, remember that you will not generally use closures in your code because they are typically generated for compiler use only, but it’s important to know what they are and what they do. Basically lexical closures allow access to the same class-level variable to multiple functions and procedures. A code example provides a better explanation. Consider the following code, in which the Divide method takes advantage of a lambda expression to calculate the division between two numbers:
Because both the Divide method and its lambda expression have access to the x local variable, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access