A group blog from members of the VB team
My name is Jared Parsons and I am a developer on the VB Compiler and Debugger. One of the features I implemented for VB 9.0 is lexical closure support. This a great addition to the VB language and I wanted to do a series of blog posts to describe this feature and how it will impact your code.
Lexical Closures (more often referred to as simply Closures) are the underpinnings for several new features in Visual Basic 9.0. The are part of the guts of Lambda and Query expressions. This will be a several part series on Closures in VB 9.0; how they work, their limitations, pitfalls surrounding their use.
To start off, let's get a basic summary of what a Closure is. Wikipedia defines it as "... a is a semantic concept referring to a function paired with an environment ...". I prefer to describe it as follows. A closure is a feature which allows users to seemlessly access an environment (locals, parameters and methods) from more than one function. Even better are samples :)
Dim x = 5
Dim f = Function(ByVal y As Integer) x + y
Dim result = f(42)
In this code we have a lambda expression which takes in a single parameter and adds it with a local variable. Lambda expressions are implemented as functions in VB (and C#). So now we have two functions, "Test" and "f", which are accessing a single local variable. This is where closures come into play. Closures are responsible for making the single variable "x" available to both functions in a process that is referred to as "lifting the variable".
To do this the compiler will take essentially 4 actions.
Public x As Integer
Function f(ByVal y As Integer) As Integer
Return x + y
Dim c As New Closure()
c.x = 5
Dim f As Func(Of Integer, Integer) = AddressOf c.f
Dim result = f(42)
Now "x" is shared amongst both functions and the user didn't have to know anything about the code we generated. You can see from this simplified example just how much code Closures and all of the other new VB 9.0 features are saving you here (Type Inference, Lambda Expressions).
Note this is only a simulation of what is generated when you use a closure, the actual generated code is much uglier and involves lots of unbindable names "$Lambda_1", etc ...
In the next part of this article I'll dive into some more uses of closures (multiple variables, method access, terminology, etc...).
Closures in VB: Part 1(The Visual Basic Team)より 今の OrcasBeta1 ではまだ VB の ラムダ式 はサポートされていないんだけれど、先回りで注意だけ。
For previous articles in this series, please see Part 1 - The basics Jared here again. This part of the
im an irania man that i wrote a programme like nero but a area of this programme faced problem . my problem is this that i cant write a function in vb.
this function is very very hard for me.
i wanna a function that write information in cd
and erase cd after writing
just this 2 function
for this reqest i will spend every mony that u want of me
iranian cant write this function
and i refer to you.
note : this function must writed in vb _ visual basic
my name is mousa basiratnia
my Id : 0123 3112284
excuse me for this that i cant speak english very good
because im poor in english
Jared here again. For previous articles in this series please see Part 1: Introduction Part 2: Method
For previous articles in this series please see Part 1: Introduction Part 2: Method Calls Part 3: Scope
For previous articles in the series please see Part 1: Introduction Part 2: Method Calls Part 3: Scope
One of my favorite new features for Code Analysis in Visual Studio 2008 is our support for analyzing
[ 原文作者 ] ： Jared Parsons [ 原文链接 ] ： Closures in VB: Part 1 我叫 Jared Parsons ，是微软ＶＢ 编译和调试组的软件开发人员。我为ＶＢ
please help me in about write cd/dvd to visual basic 6.0
Any chance you could update the posts in this series with links to the rest of the series - saves a fair bit of effort hunting for them.